15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

212<br />

Checking Your Loops<br />

understand as a result (and also harder to fix and update). So when using<br />

loops, keep these points in mind:<br />

✦ To loop a fixed number of times, use a FOR-NEXT loop.<br />

✦ To loop zero or more times, use a WHILE loop.<br />

✦ To loop at least once, use a DO loop.<br />

✦ Both WHILE and DO loops usually need a variable that’s used to check a<br />

Boolean expression to determine when the loop ends.<br />

✦ A WHILE or DO loop always needs a command that changes its Boolean<br />

expression that determines when the loop will eventually stop.<br />

✦ A loop that never stops running is an endless loop.<br />

✦ Some <strong>programming</strong> languages let you use an EXIT (or break command)<br />

to stop a loop prematurely. Use this with caution because it can make<br />

your program harder to understand.<br />

When using a loop, always make sure you know how that loop will eventually<br />

stop.<br />

Almost every program needs to use loops, so make sure you understand the<br />

differences between all the different loop variations you can use. Ultimately,<br />

loops let you run multiple commands without explicitly writing them all out,<br />

so think of loops as a <strong>programming</strong> shortcut.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!