November 2013
Beginner
325 pages
9h 47m
English
The cool kids seldom use the do-while loop, but for completeness, here it is. The do-while loop does not check the expression until it has executed the block. Thus, it ensures that the block is always executed at least once. If you rewrote the original exercise to use a do-while loop, it would look like this:
int main(int argc, const char * argv[])
{
int i = 0;
do {
printf("%d. Aaron is Cool\n", i);
i++;
} while (i < 12);
return 0;
}
Notice the trailing semicolon. That is because unlike the other loops, a do-while loop is actually one long statement:
do { something } while ( something else stays true );
Here is a flow-chart of this do-while loop:
Read now
Unlock full access