wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

FSD Looping

Total questions: 107

Worksheet time: 4hrs 34mins

Name
Class
Date
1.

What is the output?

a)

5 7 6

b)

5 6 7

c)

6 6 6

d)

5 7 7

2.

What is the output?

a)

Compile Time Error

b)

Run Time Error

c)

Hai

d)

No Hai

3.

Output?

a)

Compilation Error

b)

Run time error

c)

strings are equal

d)

not equal

4.
a)

abd

b)

cd

c)

Compile time error

d)

ab

5.
a)

abd

b)

Compile time error

c)

ab

d)

cd

6.
a)

1

b)

2

c)

1 2

d)

Run time error

7.
a)

1

b)

Hi 2

c)

Run time error

d)

2

8.
a)

7

b)

8

c)

Compile time error

d)

run time error

9.

Select different parts of "for" looping statement-

a)

Initialization part

b)

Condition Part

c)

Update part

d)

All of these

10.

What will be the output of following code- for(int i = 1; i < 5; i++ )

{

System.out.print(i);

}

a)

13

b)

135

c)

1234

d)

12345

11.

_________ in programming come into use when we need to repeatedly execute a block of statements.

a)

nested for loop

b)

none

c)

for loop

d)

loop

12.

The __________ statement uses single expression for multiple choices

a)

loop

b)

switch

c)

multiple value

d)

if else

13.
If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block? a.  b.  c. . d. 
a)
parentheses ( )
b)
braces { }
c)
brackets [ ]
d)
arrows < >
14.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

15.

In a Python program, what would be the ending value for y in the WHILE LOOP code?

a)

5

b)

51

c)

10

d)

3

16.

This statement is used to terminate the execution of the loop

a)

break

b)

jump

c)

goto

d)

continue

17.

Predict the output.

a)

320 11 330

b)

320 10 330

c)

330 11 320

18.

Predict the output

a)

5

b)

Empty Loop

c)

No Answer

d)

1234

19.

Read the program carefully and give your output

a)

Welcome Child!!!

b)
c)

Error

d)

Welcome Child!!! Welcome Child!!!Welcome Child!!!

20.

Identify the iteration statments from the following:

a)

for

b)

switch

c)

if

d)

while

e)

do while

21.

int i=1;

while(i<5)

{ cout<<i;i++; }

How many times the above loop will be executed?

a)

5

b)

1

c)

Will not be executed at all

d)

4

22.
a)

RABBIT

b)

RABBIT is printed unlimited number of times.

c)

No output

d)

Compiler error

23.
a)

GREEN

b)

RABBIT GREEN

c)

RABBIT is printed unlimited number of times.

d)

Compiler error.

24.
a)

No Output

b)

32 33 34

c)

32 33 34 35

d)

Compiler error

25.
a)

compiler error

b)

10 10 10 10 10

c)

11 12 13 14 15

d)

None of the above

26.

Write the output : -

int a;

for(a=1;i<=5;a++);

System.out.println(a); System.out.println(a);

a)

6

6

b)

1

2

3

4

5

6

6

c)

Compile time error

d)

Runtime error

27.

How many times 'Hello' is printed?

public class Test1 {

public static void main(){

for(int i = 0; i<5; i++) {

System.out.println("Hello");

break;

}

}

}

a)

1

b)

4

c)

5

d)

6

28.

What will be the output of the following program?

class Test2 {

public static void main(String s[]) {

for(int i = 0; i <= 5; i++ ) {

System.out.println("i = " + i );

}

System.out.println("i after the loop = " + i );

}

}

a)

i=0

i=1

i=2

i=3

i=4

i after the loop=5

b)

i=0

i=1

i=2

i=3

i=4

i=5

i after the loop=6

c)

i=0

i=1

i=2

i=3

i=4

i=5

i after the loop=5

d)

0=0

1=1

2=2

3=3

4=4

5=5

6 after the loop=6

29.

What will be the output of the following program?

class ForSample

{


public static void main(String s[])

{

int i = 0;

for(;i <= 5; i++ )

{

System.out.println("i = " + i );

}


System.out.println("i after the loop = " + i );

}

}

a)

i = 0

i = 1

i = 2

i = 3

i = 4

i = 5

i after the loop = 6

b)

i = 0

i = 1

i = 2

i = 3

i = 4

i = 5

i = 6

c)

Compilation Errors

d)

i = 0

i = 1

i = 2

i = 3

i = 4

i = 5

30.

What will be the output of the following program?

class ForSample

{

public static void main(String s[])

{

for(int i = 10; i <= 5; i-- )

{

System.out.println("i = " + i );

}

}

}

a)

i = 10

i = 9

i = 8

i = 7

i = 6

b)

i = 10

i = 9

i = 8

i = 7

c)

i = 6

i = 5

i = 4

i = 3

i = 2

i = 1

d)

No output

31.

What will be the output of the following program?

class Factorial

{

public static void main(String s[])

{

int number = 5;


int factorial = 1;


for(int i = 2; i <= number; i++ )

{

factorial *= factorial;

}


System.out.println("Factorial of 5 is " + factorial);

}

}

a)

Factorial of 5 is 1

b)

Factorial of 5 is 120

c)

Compilation Errors

d)

Factorial of 5 is 625

32.

What will be the output of the following program?class MultiVariableFor{

public static void main(String s[]) {

int a, b;

for(a = 1, b = 4; a < b; a++, b-)

{

System.out.println("a = " + a);

System.out.println("b = " + b);

} }}

a)

Compilation error since both a++ and b--

should not be present in the iteration section (i.e after the second semicolon)

b)

a = 1

b = 4

a = 2

b = 3

a = 3

b = 2

c)

a = 1

b = 4

a = 2

b = 3

d)

Compilation error since both a = 1 and b = 4

should not be present in the initialization section (i.e before the first semicolon)

33.

A while loop carries on as long as...

a)

The condition in the brackets is true

b)

The condition in the brackets is false

c)

i < 10

d)

the for loop has not ended

34.

How many stars are printed?

a)

7

b)

3

c)

4

d)

5

e)

Infinite Loop

35.

In Given syntax, condition refers to ________ expression

a)

int

b)

char

c)

boolean

d)

None

36.

Determine the output of this Java program.

(a)  

37.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

38.

Which of the following is considered a pre-test loop?

a)

do while

b)

if-while

c)

while

d)

if-else

39.

What is one main reason that we use loops in java?

a)

To make us suffer

b)

To help us make decisions

c)

To help us complete repetitive tasks

d)

To make java make the entire program for us.

40.

What operation should be in the blue space to print out the word Hello from the String defined as word?

(a)  

41.

How many times will the following code print the I'm Hungry? Please insert in numerical format

(a)  

42.

How many times will a do-while loop execute?

a)

One time

b)

Zero or more times

c)

One or more times

d)

Zero

43.

When should you use a for loop?

a)

if I want to check a condition every second

b)

if the number iteration is fixed

c)

if i want to run it once then check condition

d)

if i am unsure of how many times a piece of code will run

44.

What is the output of the code above?

a)

Error

b)

1 2 3 4 5 6

c)

1 2 4 9 12 15

d)

1 2 4 8 16 32

45.

What will be the output of the code?

a)

ERROR

b)

5 4 3 2 1 Blast off

c)

5 Blast off 4 Blast off 3 Blast off

2 Blast off

1 Blast off

d)

Blast off

46.

How many times will the following loop print Hello?

a)

12

b)

6

c)

15

d)

Infinite

47.

What relational operator should go in the highlighted space in order to print Hello World! five times?

(a)  

48.

Which of the following can a break statement be used in? SELECT ALL THAT APPLY

a)

Do-while loop

b)

for loop

c)

if-else block

d)

Switch Statement

49.

A loop that runs forever and can only be stopped by terminating the program is referred to as a...

a)

Run-on loop

b)

Nested Loop

c)

Terminal loop

d)

Infinite loop

50.

Simulation of code execution in which you step through instructions and track the values of the variables is referred as...

a)

Tracing

b)

Test Cases

c)

Unit Testing

d)

Pseudocode

51.

Which of the following correctly lists the elements (from Left to right) that need to be in the parenthesis of a For loop?

a)

Declare, Condition, Increment/Decrement

b)

Condition, Initialization, Looping times

c)

Initialize, Condition, Increment/Decrement

d)

Increment/Decrement, condition, intialize

52.

A pre-test loop that will run until condition is false is known as the (a)   Loop (amount of iterations is unknown)

53.

How many times will the inner for loop iterate?

(a)  

54.

What is output by the code? Pretend it says System.out.println

a)

2

b)

3

c)

4

d)

5

e)

6

55.

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

56.
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
 System.out.println("Welcome to Java");
 count++;
}
a)
8
b)
9
c)
10
d)
0
57.
What is the output of the following code?
int x = 0;
while (x < 4) {
 x = x + 1;
}
System.out.println("x is " + x);
a)
0
b)
1
c)
3
d)
4
58.

Repeating a task multiple times in programming is known as ?

a)

Iterators

b)

Scope

c)

Looping

59.

Which loop loops a set number of times?

a)

for

b)

while

c)

infinite

d)

loopy

60.

Which of these is the correct syntax for a loop?

a)

for(int i = 0; i<10; 1++){}

b)

fore(integer i = 0; i>10; i++){}

c)

for(int i = 0; i<10){}

d)

for(int i){}

61.

Which of the following is the correct way to create a String?

a)

String s = "I am cool";

b)

string string = i am cool;

c)

String s = I am cool

d)

String s = "I" am cool;

62.

Which of the following is a type of loop in Java?

a)

loop

b)

while

c)

iteration

d)

i

63.

What does the following loop print?

for(int i = 1; i<3; i++)

{ System.out.print(i); }

a)

12

b)

012

c)

0123

d)

123

64.

What will the following loop print?


int i = 0;

while (i>0)

{ System.out.println(i); }

a)

Infinite loop

b)

012345678910

c)

0

d)

Nothing

65.

What will the following loop print?

int i = 1;

while (i>0)

{ System.out.println(i); }

a)

012345678910

b)

nothing

c)

infinite loop

d)

0

66.

What does the following loop print?


for(i = i +1; i<5; int i = 0;)

{ System.out.println(i) }

a)

01234

b)

12345

c)

error

d)

0

67.

Which of the following includes the correct syntax for a for loop?

a)

for(int i = 0, i<10, i++)

b)

for(int i =0, run = 10)

c)

for(int i = 0; run = 10)

d)

for(int i = 0; i < 10; i++)

68.

for(int i; i<10; i++) {} Why won’t this code segment run?

a)

There is a missing semicolon at the end.

b)

For should be capitalized

c)

The person did not set the beginning value of i.

d)

The person did not set the ending value of i.

69.

What does this loop do?

a)

There is an error; it won’t run.

b)

It prints all the odd numbers from 0 - 20 inclusive on both ends.

c)

It prints all the even numbers from 0 - 20 inclusive on both ends.

d)

It prints all the even numbers from 0 - 20 inclusive with 0 and exclusive with 20.

70.

What loop should you use if you know how many times you are going to loop?

a)

For loop

b)

Do while loop

c)

While loop

d)

No loop

71.
What does this block of code do?
for( int i = 0; i < 10; i++)
  out.println("hello");
a)
Prints the String "hello" ten times.
b)
Prints the String "hello"
c)
Heebee Jeebies
d)
Nothing. The code does not run.
72.
Which of the loop types below IS NOT recognized in Java.
a)
while
b)
do-while
c)
for
d)
repeat
73.
Which is the index variable?
int start, qti = 0;
                   for(int i = start; i < 5; i++)
qti++;
a)
i
b)
qti
c)
start
d)
5
74.
What is an index variable in programming?
a)
A variable that changes every time a loop runs until the loop condition is false.
b)
A variable that keeps track of a textbook page number.
c)
An iterator
d)
Tomfoolery
75.
What is the loop condition for this code?
for(int i = 0; i <= 3; i++)
                out. print("sup");
a)
int i = 0
b)
i <= 3
c)
i++
d)
out.print("sup")
76.
True/False
If a loop condition is never satisfied then the loop does not execute.
a)
True
b)
False
77.
How many times will this loop run?
for(int i = 2; i < 11; i++)
        out. print("foo");
a)
7
b)
8
c)
9
d)
10
78.
How many times will this loop run?
for(int i = 0; i < 3; i++)
        out. print("foo");
a)
1
b)
2
c)
3
d)
4
79.
How many times will this loop run?
for(int i = 0; i < 10; i = i + 3)
        out. print("foo");
a)
1
b)
2
c)
3
d)
4
80.
How many times will this loop run?
for(int i = 2; i < 9; i = i + 3)
        out. print("foo");
a)
1
b)
2
c)
3
d)
4
81.
How many times will this loop run?
for(int i = 0; i < 9; i = i + 3)
        out. print("foo");
a)
1
b)
2
c)
3
d)
4
82.
How many times will this loop execute (fancy word for run)?
for(int i = 0; i > 9; i = i + 3)
                out. print("foo");
a)
0
b)
1
c)
2
d)
3
83.

A ____ structure in a Programming language allows for repetitive execution of code.

a)

procedural

b)

loop

c)

conditional

d)

none of the mentioned

84.

What type of loops is/are available in Java?

a)

for loop

b)

while loop

c)

 both for and while loops

d)

 neither for nor while loop

85.

State true or false. The correct syntax for a for loop in Java is:

for (initialization expression; test expression; update expression)

{

     // body of the loop

     // statements we want to execute

}

a)

True

b)

False

86.

How many times will “Hello World” be printed when the following code is executed?

for (int i = 1; i <= 5; i++)

            System.out.println("Hello World");

a)

4 times

b)

5 times

c)

0 times

d)

Error

87.

What will be the output of the following code?

int sum = 0;

for (int x = 1; x <= 5; x++) {

     sum = sum + x;

     }

System.out.println("Sum: " + sum);

a)

15

b)

5

c)

10

d)

Error

88.

Which is the right syntax for the while loop?

a)

WHILE bacon <= 5 { cout << "text"; }

b)

while bacon <= 5 cout << "text";

c)

while (bacon <= 5) { cout << "text"; }

89.

Fill in the blanks.

(a)  

90.

เติมส่วนของโปรแกรมในช่องว่าง เพื่อเพิ่มค่าให้ตัวแปร bacon ครั้งละ 2 แล้วแสดงผลออกมาเรื่อยๆ

(a)  

91.

เติมส่วนของคำสั่ง เพื่อรับค่าจำนวนเต็ม 5 จำนวน

และหาผลรวมของจำนวนเหล่านั้น

โดยเก็บผลรวมไว้ในตัวแปร total

(a)  

92.

loop do...while ข้อใดถูกต้อง

a)

do { } while (test);

b)

doo while(test)

c)

DO while test;

93.

เติมส่วนของโปรแกรม เพื่อแสดงค่าของตัวแปร x 10 ครั้ง

(a)  

94.

How is a "do... while" loop different from a "while" loop?

a)

while loop runs the code before testing the condition

b)

do...while loop runs your code at least one time

c)

do...while loop tests the condition before running the code

95.

เติมส่วนของโปรแกรม เพื่อพิมพ์ข้อความ

"this is a loop" จำนวน 15 ครั้ง

(a)  

96.

Print i as long as i is less than 6.

(a)  

97.

Use the do/while loop to print i as long as i is less than 6.

(a)  

98.
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
 System.out.println("Welcome to Java");
 count++;
}
a)
8
b)
9
c)
10
d)
0
99.
What is the output of the following code?
int x = 0;
while (x < 4) {
 x = x + 1;
}
System.out.println("x is " + x);
a)
0
b)
1
c)
3
d)
4
100.

Repeating a task multiple times in programming is known as ?

a)

Iterators

b)

Scope

c)

Looping

101.

Which of the following is a type of loop in Java?

a)

loop

b)

while

c)

iteration

d)

i

102.

What will the following loop print?


int i = 0;

while (i>0)

{ System.out.println(i); }

a)

Infinite loop

b)

012345678910

c)

0

d)

Nothing

103.

The body of a while loop will run as long as the test condition is "false".

a)

True

b)

False

104.

How many times will this loop body run?

a)

0

b)

infinitely many times

c)

5

d)

it depends on what the user inputs

105.
How many times will the following code print "Welcome to Java"?
int count = 0;
do {
 System.out.println("Welcome to Java");
 count++;
} while (count < 10);
a)
0
b)
9
c)
8
d)
10
106.

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

a)

do-while

b)

while

c)

for

d)

none of the mentioned

107.

What will this code display?


int i = 0;

while (i < 5) {

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

i ++;

} ;

a)

0, 0, 0, 0, 0, 0, 0, 0, (repeat forever)

b)

0, 1, 2, 3, 4,

c)

1, 2, 3, 4, 5,

d)

Compile error

e)

10,