Published online by Cambridge University Press: 17 July 2025
In the last two chapters, we have learnt to develop programs that used simple sequential statements or conditional statements. In the first case, each statement in the program is executed in a fixed order; whereas in the second case, depending on some condition a particular set of statements gets executed, skipped or another set of statements gets executed. But most of the time we have to execute same series of actions. The mechanism, which helps us to perform an action over and over, is the ‘loop’ or ‘iteration’.
Loops are of two types, entry controlled loop and exit controlled loop. When condition is checked before the execution of the body of the loop, it is called entry controlled loop or pre-test iteration. It is described by the following block diagram.
As the block diagram described, first condition will be checked. If the condition is true, the control will enter in the loop and body of the loop will execute. Then control will loop back and the condition will be tested again. This process will be continued until the condition becomes false. When the condition becomes false, control will terminate the loop and execute the next statement followed by the loop statement.
But when condition is checked after the execution of the body of the loop, it is called exit controlled loop or post test iteration. Here, first body of the loop will execute. Then condition will be checked to determine whether the loop will execute next time or not. If the condition is true, the control will loop back. When the condition becomes false, control will terminate the loop and execute the next statement followed by the loop statement. It is described by the following block diagram.
To save this book to your Kindle, first ensure no-reply@cambridge-org.demo.remotlog.com is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.