Summary
Sequence, selection, and iteration are the three pillars that programming rests upon, and, in this chapter, we have covered the latter two.
Selection is when we test values in variables using a condition that can be either true or false. If our test turns out to be true, we can let the program execute a block of code. If it turns out to be false, we can have another block that only runs if in the case. This is done with the help of if
statements.
Sometimes, we have multiple options to choose from, and we need to pick one. We could then use a switch
statement. Using it instead of an if
statement can make your code less verbose and easier to read.
The common task of repetition can be done in at least four ways, with the most common being the for
loop. This loop will let us iterate a fixed number of times.
When we don't know how many times we want to iterate, we can use either a while
loop or a do while
loop. They will both iterate as long as a condition is true...