0% found this document useful (0 votes)
42 views4 pages

Exam Modulo 6

This document contains true/false questions about Java loops. It discusses the following key points: - A do-while loop will always execute statements in the loop at least once. - A for loop evaluates its initialization, condition, and update expressions in the header before each iteration. - The break statement terminates the current loop and continues execution with the statement following the loop.

Uploaded by

XIOMARA JIMÉNEZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

Exam Modulo 6

This document contains true/false questions about Java loops. It discusses the following key points: - A do-while loop will always execute statements in the loop at least once. - A for loop evaluates its initialization, condition, and update expressions in the header before each iteration. - The break statement terminates the current loop and continues execution with the statement following the loop.

Uploaded by

XIOMARA JIMÉNEZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

A do-while will always execute statements contained in the loop at least


once.
True (*)
False
Correct
(1/1) Points
2. What is the output?

public static void main(String[] args) {


int num = 1;
while (num >= 200){
System.out.print(num + "" "");
num = num * 5;
}
}
1 5 25 125
5 25 125
1 5 25 125 175
No output. (*)
Incorrect. Refer to Section 6 Lesson 2.
(0/1) Points
3. A while loop is often used with Scanner input as you don't know many times
you'll need to re-prompt the user if they type bad data.
True (*)
False
Correct
(1/1) Points
4. A post-test loop evaluates its condition at the end of the loop instead of the
beginning.
True (*)
False
Correct
(1/1) Points
5. After the loop is terminated, the statement immediately following the loop
body is executed.
True (*)
False
Correct
6. A pre-test loop evaluates the condition prior to execution of the loop.
True (*)
False
Correct
(1/1) Points
7. Given:

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


What type of variable is i?

Member
Static
Local (*)
Global
Incorrect. Refer to Section 6 Lesson 1.
(0/1) Points
8. In the given syntax of for loop, which part represents the header section?

for (initialization; condition; update) {


// Code statement(s) }
for (initialization; condition; update) (*)
Code statement(s)
for (initialization; condition; update) { Code statement(s) }
for (initialization; condition; update) { }
Correct
(1/1) Points
9. Which is not a looping statement in Java?
while
for
switch (*)
do-while
Correct
(1/1) Points
10. Each expression in the header section of a for loop is optional.
True (*)
False
Correct
(1/1) Points
11. What is the result?

public static void main(String[] args) {


for (;;) {
System.out.println("Welcome to Java");
}
}
No error and no output.
Program prints "Welcome to Java" once.
Program prints "Welcome to Java" an infinite number of times. (*)
Compilation error as expressions are missing in the for loop.
Correct
(1/1) Points
12. You need to calculate the squares of numbers from 1 to 5. Which of the
items should be present in your looping statement?
Initialization Expression , Condition Expression , Update Expression (*)
Initialization Expression , Condition Expression
Initialization Expression , Update Expression
Condition Expression , Update Expression
Correct
(1/1) Points
13. The only way to exit a loop is for the loop condition to evaluate to false.
True
False (*)
Correct
(1/1) Points
14. Which is used to terminate a loop?
break (*)
switch
continue
catch
Correct
(1/1) Points
15. Which two statements are true about the break statement?
(Choose all correct answers)
The execution of the program will continue with the statement following the
loop-statement. (*)
The execution of the program will stop at the statement following the loop-
statement.
When a break statement is executed inside a loop, the loop-statement is
terminated immediately and comes out of the program.
When a break statement is executed inside a loop, the loop-statement is
terminated immediately. (*)
Correct

You might also like