Computer Program Reading Comprehension Project
U of T Computer Program Reading Comprehension Project
Simple While Loop


This is a simple example, on the execution and purpose of while loops.

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


SimpleWhileLoop.java
1int m = 5;
2int n = 0;
3
4while (m > n)
5{
6     System.out.println (m + . . + n );
7     m--;
8     n++;
9}
10
Displaying 10 of 10 lines
View full source


Question 1
When does the while loop terminate?
int a;
Solution

Question 2
What is the output of the code?
Hints Solution

Question 3
How many times is the while loop executed?
Hints Solution

Question 4
How many times is the condition m>n checked?
Solution

Question 5
What are the values of m and n, when the while loop finishes?
Hints Solution