Skip to main content Accessibility help
Internet Explorer 11 is being discontinued by Microsoft in August 2021. If you have difficulties viewing the site on Internet Explorer 11 we recommend using a different browser such as Microsoft Edge, Google Chrome, Apple Safari or Mozilla Firefox.

Chapter 10: Loop Statements

Chapter 10: Loop Statements

pp. 171-223

Authors

, Techno India Hooghly, West Bengal, , Techno India College of Technology, West Bengal
  • Add bookmark
  • Cite
  • Share

Extract

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.

About the book

Access options

Review the options below to login to check your access.

Purchase options

Paperback
US$105.00

Have an access code?

To redeem an access code, please log in with your personal login.

If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.

Also available to purchase from these educational ebook suppliers