break statement in C
The break statement in C programming language has following two usage:
Syntax:
The syntax for a break statement in C is as follows:
Flow Diagram:
Example:
When the above code is compiled and executed, it produces following result:
The break statement in C programming language has following two usage:
- When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.
- It can be used to terminate a case in the switch statement (covered in the next chapter).
Syntax:
The syntax for a break statement in C is as follows:
break;
Flow Diagram:
Example:
#include <stdio.h>
int main ()
{
/* local variable definition */
int a = 10;
/* while loop execution */
while( a < 20 )
{
printf("value of a: %d\n", a);
a++;
if( a > 15)
{
/* terminate the loop using break statement */
break;
}
}
return 0;
}
When the above code is compiled and executed, it produces following result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
Post a Comment