The do-while loop

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:

i​n​t​ ​m​a​i​n​(​i​n​t​ ​a​r​g​c​,​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​ ​a​r​g​v​[​]​)​
{​
 ​ ​ ​ ​i​n​t​ ​i​ ​=​ ​0​;​
 ​ ​ ​ ​d​o​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​p​r​i​n​t​f​(​"​%​d​.​ ​A​a​r​o​n​ ​i​s​ ​C​o​o​l​\​n​"​,​ ​i​)​;​
 ​ ​ ​ ​ ​ ​ ​ ​i​+​+​;​
 ​ ​ ​ ​}​ ​w​h​i​l​e​ ​(​i​ ​<​ ​1​2​)​;​
 ​ ​ ​ ​r​e​t​u​r​n​ ​0​;​
}​

Notice the trailing semicolon. That is because unlike the other loops, a do-while loop is actually one long ...

Get Objective-C Programming: The Big Nerd Ranch Guide 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.