C break statement

  • Using break keyword, we can terminate loop body or switch body.
  • Using break keyword is always optional, but it should be placed within the loop body or switch body only.
  • In implementation where we know the the maximum number of repetition but some condition is there where we need to terminate the loop body then go for break

.

Examples:

void main()
{
int a;
a=1;
while(a<=10) { printf("%d",a); if(a>3)
break;
++a;
}
}

Explanation for above program:

  • Whenever value of a become 4 then condition becomes true, then break statement will be executed.
  • Whenever the break statement is executed automatically control will pass outside of the loop body.
Powered by k2schools