January 2003
Beginner to intermediate
1200 pages
23h 42m
English
Using loops, you can execute code as many times as you want—which is one of the things computers excel at. The most basic loop is the for loop statement, and here's what this statement looks like in general:
for (initialization; test; increment) { code }
Here's what's happening: You place an expression in the initialization part of the for loop (which often initializes a variable, called a loop index, to 0), Then you insert a test condition in the test part of the loop to be tested each time the code in the loop has been executed. If the test is false, the loop ends (often the test condition checks whether the value in the loop index exceeds a specified maximum value). On the other hand, if the test condition ...