Skip to main content Accessibility help
×
Hostname: page-component-5447f9dfdb-56ltz Total loading time: 0 Render date: 2025-07-28T16:59:29.383Z Has data issue: false hasContentIssue false

10 - Loop Statements

Published online by Cambridge University Press:  17 July 2025

Subrata Saha
Affiliation:
Techno India Hooghly, West Bengal
Subhodip Mukherjee
Affiliation:
Techno India College of Technology, West Bengal
Get access

Summary

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.

Information

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2016

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Book purchase

Temporarily unavailable

Accessibility standard: Unknown

Accessibility compliance for the PDF of this book is currently unknown and may be updated in the future.

Save book to Kindle

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.

Available formats
×

Save book 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 Dropbox.

Available formats
×

Save book to Google Drive

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.

Available formats
×