wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Loops

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

What will the output of the following code segment be?


int a = 1, b = 2;

System.out.println(++a+”,”+b++);

a)

1,2

b)

2,2

c)

2,3

d)

3,3

2.

What will the following program segment display?


for(int a = 2; a <= 10; a += 3)

System.out.print(a+””);

a)

2 5 8

b)

2 5

c)

2 5 8 11

d)

2

3.

In the expression number++, the ++ operator is in what mode?

a)

prefix

b)

pretest

c)

postfix

d)

posttest

4.

What is each repetition of a loop known as?

a)

cycle

b)

revlolution

c)

orbit

d)

iteration

5.

This is a variable that controls the number of iterations performed by a loop.

a)

loop control variable

b)

accumulator

c)

iteration register variable

d)

repetition meter

6.

The while loop is this type of loop.

a)

pretest

b)

posttest

c)

prefix

d)

postfix

7.

The do-while loop is this type of loop.

a)

a. pretest

b)

b. posttest

c)

c. prefix

d)

d. postfix

8.

The for loop is this type of loop.

a)

a. pretest

b)

b. posttest

c)

c. prefix

d)

d. postfix

9.

This type of loop has no way of ending and repeats until the program is interrupted.

a)

a. indeterminate

b)

b. interminable

c)

c. infinite

d)

d. timeless

10.

This expression executes at the end of each iteration of the for loop.

a)

a. initialization expression

b)

b. test expression

c)

c. update expression

d)

d. statement block

11.

This expression is executed by the for loop only once, regardless of the number of iterations.

a)

a. initialization expression

b)

b. test expression

c)

c. update expression

d)

d. preincrement expression

12.

This statement causes a loop to terminate early.

a)

a. continue

b)

b. break

c)

c. switch

d)

d. none of the above