The do Statement

The two looping constructs discussed thus far in this chapter both test the conditions before the loop is executed. Therefore, the body of the loop might never be executed if the conditions are not satisfied. When developing programs, you sometimes want to have the test made at the end of the loop instead of at the beginning. Naturally, the Objective-C language provides a special language construct to handle such a situation, known as the do statement. The syntax of this statement is as follows:

do   program statementwhile ( expression );

Execution of the do statement proceeds as follows: program statement is executed first. Next, the expression inside the parentheses is evaluated. If the result of evaluating expression is ...

Get Programming in Objective-C, Sixth Edition 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.