wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Loops - I

Total questions: 10

Worksheet time: 3mins

Name
Class
Date
1.

int i = 5;

while (i > 5) {

System.out.print(i);

i--;

}

What is the output?

a)

5

b)

Infinite loop

c)

No output

d)

Compilation error

2.

int i = 5;

do {

System.out.print(i);

i--;

} while (i > 5);

What is the output?

a)

No Output

b)

5

c)

54

d)

Infinite loop

3.

int i = 1;

while (true) {

if (i == 3)

break;

System.out.print(i);

i++;

}

a)

123

b)

12

c)

1

d)

Infinite loop

4.

int i = 1;

while (i <= 5) {

if (i == 4)

break;

System.out.print(i);

i++;

}

a)

123

b)

1234

c)

12345

d)

124

5.

int i = 10;

do {

System.out.print(i + " ");

i++;

} while (i < 10);

a)

No Output

b)

10

c)

11

d)

Infinite loop

6.

int i = 1;

while (i <= 3) {

int j = 1;

while (j <= 3) {

if (i == j)

break;

System.out.print(j);

j++;

}

i++;

}

a)

123123

b)

121

c)

12

d)

112233

7.

int i = 1;

while (i <= 5) {

System.out.print(i);

if (i == 3)

break;

i++;

}

a)

123

b)

12345

c)

12

d)

Infinite loop

8.

int i = 5;

while (i > 0) {

System.out.print(i);

i--;

if (i == 2)

break;

}

a)

54321

b)

543

c)

54

d)

5

9.

int i = 0;

do {

System.out.print("A");

break;

} while (i < 5);

a)

AAAAA

b)

A

c)

No output

d)

Infinite loop

10.

int i = 1;

while (i <= 3) {

System.out.print(i);

i++;

break;

}

a)

123

b)

1

c)

No output

d)

Infinite loop