14ITERATIVE CONTROL STRUCTURES

image

Most programs spend the majority of their time executing machine instructions within a loop. Therefore, if you want to improve your applications’ execution speed, first you should see if you can improve the performance of the loops in your code. This chapter will describe the following varieties of loops:

  • while loops

  • repeat..until/do..while loops

  • forever (infinite) loops

  • for (definite) loops

14.1 The while Loop

The while loop is perhaps the most general-purpose iterative statement that HLLs provide, so compilers generally work hard at emitting optimal code for it. The while loop tests a Boolean expression at the ...

Get Write Great Code, Volume 2, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.