mikroC

mikroC - C Compiler for Microchip PIC microcontrollers

making it simple...

 

 

 

 

Do Statement

The do statement executes until the condition becomes false. Syntax of do statement is:

do statement while (expression);

The statement is executed repeatedly as long as the value of expression remains non-zero. The expression is evaluated after each iteration, so the loop will execute statement at least once.

Parentheses around expression are mandatory.

Note that do is the only control structure in C which explicitly ends with semicolon (;). Other control structures end with statement which means that they implicitly include a semicolon or a closing brace.

Here is an example of calculating scalar product of two vectors, using the do statement:

s = 0; i = 0; do {

s += a[i] * b[i]; i++;

} while (i < n);

page

120

For Statement

The for statement implements an iterative loop. Syntax of for statement is:

for ([init-exp];[condition-exp];[increment-exp])statement

Before the first iteration of the loop, expression init-expsets the starting variables for the loop. You cannot pass declarations in init-exp.

Expression condition-expis checked before the first entry into the block; statement is executed repeatedly until the value of condition-expis false. After each iteration of the loop, increment-expincrements a loop counter. Consequently, i++ is functionally the same as ++i.

MikroElektronika: Development tools - Books - Compilers