Skip to content
ExamSpine

Lesson 3.2 · Answer it

Find infinite loop

3 marksYou mark it yourself against the marking points

A student wrote this program to print every number from 1 to 5:

n = 1
while n <= 5:
    print(n)
int n = 1;
while (n <= 5) {
    System.out.println(n);
}

(a) State what happens when the program runs. [1]

(b) State what is missing from the loop body that causes this problem. [1]

(c) Write the one line that should be added, and state where it goes. [1]

[3]