Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

The For Loop

The for loop is a fixed iterative loop. The loop will be used to do some task a predetermined number of times. Although its syntax varies from language to language, certain aspects of the for loop are the same. For one thing, it always has the word “for” mentioned at the beginning of the loop. The other characteristic of this loop is that you can figure out how many times it will spin before it is executed.

Before you construct a for loop you must decide what statement or statements you wish to iterate—that is, repeat. Then you need to know how many times you want to execute them. Once you decide, you can begin to construct the loop. You will need to declare a variable called a control variable that will aid you in the execution of the loop.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial