217k views
1 vote
what are the three sections inside the parentheses of a for loop header typically used for? describe what each clause does to control the execution of the for loop.

User Nick Benes
by
3.2k points

1 Answer

0 votes

Answer:

The first section initializes a loop variable

The second section puts an upper limit on the value of this loop counter to control the number of times the loop is executed

The third section determines how much the loop counter should be incremented by for the next iteration of the for loop

Step-by-step explanation:

I presume this relates to C, C++, Java etc because Python has a totally different loop header structure

The first section initializes a loop variable

The second section puts an upper limit on the value of this loop counter to control the number of times the loop is executed

The third section determines how much the loop counter should be incremented by for the next iteration of the for loop

Ex:
for(int i = 0; i < 10; i++){

}
First section i =0 initializes the loop counter variable to 0
Second section i < 10 tells the loop to keep executing until loop counter becomes 9 because the next iteration will be at the value of 10 and loop terminates

The third section increments the loop counter by 1 for the next iteration of the loop

The loop will execute 10 times for each of the loop counter values 0, 1, 2,3, ,4 ,5, 6, 7, 8, 9

User DChhapgar
by
3.3k points