Computer Program Reading Comprehension Project
U of T Computer Program Reading Comprehension Project
The Basic For-Loop
The for-loop on this page is an example of a very common idiom in Java. The questions for this loop review the fundamental terms, concepts and qualities of for-loops. These questions can be asked about any for-loop, and many will be asked about more complicated loops elsewhere on this site.

Download files: TheBasicForLoop.java
Areas: Introduction to loops.


TheBasicForLoop.java
1for (int i = 0; i < 30; i++)
2    {
3    System.out.println (i);
4    }


Question 1
What is the body of the loop?
Hints Solution

Question 2
What is the test of the loop?
Solution

Question 3
What is the loop counter?
Solution

Question 4
What is the step-size of the loop?
Solution

Question 5
What is the starting value of the loop counter?
Solution

Question 6
What is the value of the loop counter the last time the loop is executed?
Solution

Question 7
What does the body of the loop do?
Solution

Question 8
What does the loop do?
Solution

Question 9
What is the value of i after the loop exits?
Solution

Question 10
What is the value of the loop counter the last time it is tested?
Solution

Question 11
Where in the code is the loop counter incremented?
Solution

Question 12
When during execution is the loop counter incremented?
Solution

Question 13
Where in the code is the loop counter tested?
Solution

Question 14
When during execution is the loop counter tested?
Solution

Question 15
How many times will the body of the loop be executed?
Solution

Question 16
How many times will the test be evaluated?
Solution

Question 17
How many times will the loop counter be incremented?
Solution

Question 18
Where is the loop counter declared?
Solution

Question 19
Where in the code is the loop counter initialized?
Solution

Question 20
How many ways are there for the loop to exit?
Solution

Question 21
Which parts of this code can cause the loop to exit?
Solution

Question 22
Under what conditions will this loop exit?
Solution