Representing a for Statement with an Equivalent while Statement
The for
statement often can be represented with an equivalent while
statement as follows:
initialization;while (loopContinuationCondition){ statement increment;}
In Section 5.8, we show a case in which a for
statement cannot be represented with an equivalent while
statement. Typically, for
statements are used for counter-controlled repetition and while
statements for sentinel-controlled repetition. However, while
and for
can each be used for either repetition type.
Get Java™ How To Program (Early Objects), Tenth 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.