Chapter 5: C Control Flow
and expression3 are assignments or function calls and
xpression2 is a test of some sort. The expressions can be any expression
cluding the empty expression which is nothing followed by a semicolon:
for(;;)
{
// Do stuff forever
}
This is an alternative way to do the while(1) eternal loop.
You can usually accomplish the same goal using either while or for statements.
Generally it is clearer to use for loops with a simple initialization and
incrementing such as:
for(int i = 1; i <= 128; i = i*2)
{
// Do stuff while I less than or equal 128
}
But its really a matter of personal preference though most C dudes will want to
smack you around a little if you don’t do it their way.
While and for loops test for the termination condition before running the block,
‘do while’ runs the block first insuring that the block will be run at least once:
do
{
// Do stuff at least once
}
while(expression);
Break and Continue.......................................................................................
A break statement throws you out of the loop immediately and without regard for
the terminating expression. It only throws you out of the innermost loop in nested
loops.
Usually expression1
e
in