User`s manual
Dynamic C User’s Manual digi.com 41
Here, there is no initial condition, no end condition, and no stepping expression. The loop body (some
statement(s)) continues to execute endlessly. An endless loop can also be achieved with a while loop.
This method is slightly less efficient than the for loop.
4.18.2 Continue and Break
Two keywords are available to help in the construction of loops: continue and break.
The continue statement causes the program control to skip unconditionally to the next pass of the loop.
In the example below, if bad is true, more statements will not execute; control will pass back to the top of
the while loop.
The break statement causes the program control to jump unconditionally out of a loop. In the example
below, if cond_RED is true, more statements will not be executed and control will pass to the next state-
ment after the ending curly brace of the for loop
The break keyword also applies to the switch/case statement described in the next section. The
break statement jumps out of the innermost control structure (loop or switch statement) only.
There will be times when break is insufficient. The program will need to either jump out more than one
level of nesting or there will be a choice of destinations when jumping out. Use a goto statement in such
cases. For example,
while(1) { some statement(s) }
get_char();
while( ! EOF ){
some statements
if( bad ) continue;
more statements
}
for( i=0;i<n;i++ ){
some statements
if( cond_RED ) break;
more statements
}
while( some statements ){
for( i=0;i<n;i++ ){
some statements
if( cond_RED ) goto yyy;
some statements
if( code_BLUE ) goto zzz;
more statements
}
}
yyy:
handle cond_RED
zzz:
handle code_BLUE