Using for Loopsfor loops are written to execute a loop for a fixed number of times. for loops are very powerful constructs. They are divided into three parts . The first part is the initialization part. In the initialization part you can declare multiple variables that can be used as part of the loop. The second part of the for loop is the test part. The loop continues to execute while the test part is equal to true. The third part of the for loop is the execution part. At the end of each loop the code will execute the third portion of the for statement. When wanting to execute a series of statements in a loop a certain number of times a variable that serves as the counter is initialized in the first part of the statement; the second part of the statement tests to see if the counter variable is below a certain value; and the third part of the statement increases the counter by one in each iteration. To write a for loop that executes for a specified number of times:
Tip
|