Name
do ... while
Synopsis
The do ... while
statement is a
“bottom-driven” loop: first the
body of the loop is executed, then the controlling expression is
evaluated. This is repeated until the controlling expression is
“false”, or 0
.
The key difference from a while
statement is that
a do ... while
loop body is always executed at
least once. A while
loop may not execute at all,
because its expression could be false to begin with.
Syntax:
dostatement
while (expression
) ;
Example:
i = 0; do // Copy the string str1 str2[i] = str1[i]; // to string str2 while ( str1[i++] != '\0' );
Get C Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.