- Introduction to C
- Introduction to C
- Program Structure
- Basic Syntax
- Data Types
- Input/Output
- Operators
- Variables
- Storage Classes
- If statements
- Loops
- Case control statements
- Pointer
- Structures
- Union
- Functon
- Array
- Strings
- File I/O
- Type Casting
- Command line arguments
- Header Files
- Enumeration
- Dynamic memory allocation
- Preprocessor
- Recursion
- Error Handling
Case control statements
Statements that are used to execute only specific block of statements in a series of blocks are called case control statements.
There are following 4 types of case control statements in C language. They are,
1.switch
2.Break
3.Continue
4.goto
Switch case statement in C:
Switch case statements are used to execute only specific case statements based on the switch expression or condition. It is an abstract version of if else ladder.
Below given the syntax for switch case statement.
Demo
int main ()
{
int value = 3;
switch(value)
{
case 1:
printf("Value is 1 \n" );
break;
case 2:
printf("Value is 2 \n" );
break;
case 3:
printf("Value is 3 \n" );
break;
case 4:
printf("Value is 4 \n" );
break;
default :
printf("Value is other than 1,2,3,4 \n" );
}
return 0;
} RUN
break statement in C:
Break statement is mainly used to terminate the switch case,while loop and for loop from the subsequent execution.
Syntax: break;
Demo
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==7)
{
printf("\nTerminate for loop when i = 7");
break;
}
printf("%d ",i);
}
} RUN
Continue statement in C:
Continue statement is used to jump the current iteration and continue the next iteration of for loop, while loop and do-while loops. So, in that the remaining statements are skipped within the loop for that particular iteration.
Syntax : continue;
Demo
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==4 || i==5)
{
printf("\nSkipping %d from display using " \
"continue statement \n",i);
continue;
}
printf("%d ",i);
}
} RUN
goto statement in C:
goto statements is used to transfer the control of a program to the specified label in the program.
Syntax for goto statement in C.
.....
go to label;
......
......
LABEL:
statements;
}
Demo
int main()
{
int p;
for(p=0;p<10;p++)
{
if(p==7)
{
printf("\nWe are using goto statement when p = 7");
goto TUTON;
}
printf("%d ",p);
}
TUTON : printf("\nNow, we are inside label name \"tuton\" \n");
} RUN