Professional Documents
Culture Documents
ID: 524083
CpE112 (1779)
For loops: When you want complete control over every part of the loop, these are the ones you choose.
For loops are what you need if your looped task needs to know what step it's on, where it's heading, and
how fast it's getting there. When you know exactly how many steps you want your loop to take, use a
for loop. With for loops, there's an iterator, a condition, and an increment. The latter is the same as the
while and do-while loops' condition. The increment is the amount that the iterator changes after each
iteration, and the iterator is an integer variable that reflects your iterating location.
While loops: These are used when you want to keep doing a block of work as long as a certain condition
is met, no matter how many times it occurs. To describe this loop into words, you'd say, "do Y for as long
Do while loops: They're similar to while loops, as the name implies. Do-while loops, on the other hand,
are guaranteed to run only once. In do while loops, what you get is just like while loops, the only
difference is that the block will run once before the expression is evaluated.