212 Checking Your Loops understand as a result (and also harder to fix and update). So when using loops, keep these points in mind: ✦ To loop a fixed number of times, use a FOR-NEXT loop. ✦ To loop zero or more times, use a WHILE loop. ✦ To loop at least once, use a DO loop. ✦ Both WHILE and DO loops usually need a variable that’s used to check a Boolean expression to determine when the loop ends. ✦ A WHILE or DO loop always needs a command that changes its Boolean expression that determines when the loop will eventually stop. ✦ A loop that never stops running is an endless loop. ✦ Some programming languages let you use an EXIT (or break command) to stop a loop prematurely. Use this with caution because it can make your program harder to understand. When using a loop, always make sure you know how that loop will eventually stop. Almost every program needs to use loops, so make sure you understand the differences between all the different loop variations you can use. Ultimately, loops let you run multiple commands without explicitly writing them all out, so think of loops as a programming shortcut.
Chapter 6: Breaking a Large Program into Subprograms In This Chapter Using a subprogram Passing parameters Using recursion The bigger the program, the harder that program is to read, fix, and modify. Just as it’s easier to spot a spelling mistake in a recipe printed on a single page compared to trying to find that same spelling mistake buried inside a 350-page cookbook, so is it easier to fix problems in a small program than a big one. Because small programs can perform only simple tasks, the idea behind programming is to write a lot of little programs and paste them together, like building blocks, creating one massive program. Because each little program is part of a much bigger program, those little programs are subprograms, as shown in Figure 6-1. The biggest problem with dividing a large program into multiple subprograms is to make each subprogram as independent, or loosely coupled, as possible. That means if one subprogram fails, it doesn’t wreck the entire program along with it, like yanking out a single playing card from a house of cards. One major advantage of subprograms is that you can isolate common program features in a subprogram that you can copy and reuse in another program. For example, suppose you wrote a word processor. Although you could write it as one massive, interconnected tangle of code, a better approach might be dividing the program functions into separate parts. By doing this, you could create a separate subprogram for ✦ Displaying pull-down menus ✦ Editing text ✦ Spell checking ✦ Printing a file
Agreed in 2016, the motive of the General Data Protection Regulation (GDPR) is to better protect the personal data of European Union “data subjects” – EU citizens and other nationals physically present in the EU at the time data are collected. Visit: https://www.hipaajournal.com/gdpr-training/