Instructions
182Compiler
© 2013 Conrad Electronic
{
a=a*2;
x=a;
} while(a);
The essential difference between the do .. while loop and the normal while loop is the fact that
in a do .. while loop the instruction is executed at least once.
break Instruction
A break instruction will leave the loop and the program execution will start with the next instruction
after the do .. while loop.
continue Instruction
When executing continue within a loop there will immediately be a new calculation of the Expres-
sion. Depending on the result the loop will be repeated at unequal 0. At a result of 0 the loop will be
terminated.
Example:
do
{
a++;
if(a>10) break; // will terminate loop
} while(1); // endless loop
4.2.6.3 for
A for loop is normally used to program a definite number of loop runs.
for(Instruction1; Expression; Instruction2) Instruction3;
At first Instruction1 will be executed which normally contains an initialization. Following the evalu-
ation of the Expression takes place. If the Expression is unequal 0 Instruction2 and Instruction3 will
be executed and the loop will repeat itself. When Expression reaches the value 0 the loop will be ter-
minated. As with other loop types at Instruction3 an Instruction Block can be used instead of a
single instruction.
for(i=0;i<10;i++)
{
if(i>a) a=i;
a--;
}
It must be observed that variable i will within the loop run through values 0 through 9 rather than 1
through 10!