Search
Loops

Loops

As you may have already noticed, the act of enciphering or deciphering a message will involve a lot of repeated operations. You're likely to get tired of adding and subtracting by hand! When programming, its often impractical or impossible to type out every individual operation that needs to be performed. Instead, a programmer can find some sort of structure in the repeated operations that can be used to describe the series of operations that need to be performed. One way to do that is to use a loop to iterate through all the different operations. There are two types of loops covered in this section, the while loop and the for loop. All loops will continually run a line or lines of code until a particular condition has been met. Both types of loops have their advantages and disadvantages depending on what problem you're trying to solve. We'll soon see how loops will be helpful in automating the enciphering and deciphering process for a collection of letters while providing flexibility of our code to handle a variety of messages.