Section 6 - Loop Constructs

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the result? public static void main(String[] args) { for (;;) { System.out.println("Welcome to Java"); } } a)Program prints "Welcome to Java" an infinite number of times. b)Program prints "Welcome to Java" once. c)Compilation error as expressions are missing in the for loop. d)No error and no output.

a)Program prints "Welcome to Java" an infinite number of times.

A continue statement is used to skip the remaining statements in the body of a loop and continue with the next iteration of the loop. a)True b)False

a)True

A do-while will always execute statements contained in the loop at least once. a)True b)False

a)True

A pre-test loop evaluates the condition prior to execution of the loop. a)True b)False

a)True

Looping continues as long as the boolean expression in the for loop is false. a)True b)False

b)False

Which two statements are true about the while loop. a)The statements of a while loop will execute one or more times. b)The statement in a while loop will execute zero or more times. c)If the condition of the loop is true initially, the statements are never executed. d)If the condition of a pre-test loop is false, the statements in the loop are never executed.

b)The statement in a while loop will execute zero or more times. d)If the condition of a pre-test loop is false, the statements in the loop are never executed.

Which two statements are true about the break statement? a)When a break statement is executed inside a loop, the loop-statement is terminated immediately and comes out of the program. b)When a break statement is executed inside a loop, the loop-statement is terminated immediately. c)The execution of the program will continue with the statement following the loop-statement. d)The execution of the program will stop at the statement following the loop-statement.

b)When a break statement is executed inside a loop, the loop-statement is terminated immediately. c)The execution of the program will continue with the statement following the loop-statement.

Which two are valid syntax to create a for loop? a)for(int i = 10 i >= 0; i++ ) { System.out.println("i="+i); } b)for(int i = 10; i >= 0; i++ ) { System.out.println("i="+i); } c)for(int i = 10; i >= 0; ) { System.out.println("i="+i); } d) for(int i = 10, i >= 0, i++ ) { System.out.println("i="+i); }

b)for(int i = 10; i >= 0; i++ ) { System.out.println("i="+i); } c)for(int i = 10; i >= 0; ) { System.out.println("i="+i); }

Which is not a looping statement in Java? a) for b) do-while c) Switch d) while

c) Switch

When is an update expression in a for loop executed? a)Before each iteration through the loop. b)After two iterations through the loop. c)Before the first iteration through the loop. d)After each iteration through the loop.

d)After each iteration through the loop.


Kaugnay na mga set ng pag-aaral

Chapter 17: Nursing Care of the Newborn at Risk

View Set

Nursing Assisting Chapter 21 - The Musculoskeletal System

View Set

Ch. 13-Disorders of Red Blood Cells

View Set

Organic Chemistry Lab Quiz 5: Experiment 7-10 + Spectra

View Set

10-2 Guided Reading Activity - Christianity and Medieval Civilization

View Set