Do Statement
The do
statement executes until the condition becomes false. The syntax of the 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 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 );
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
What do you think about this topic ? Send us feedback!