Which loop in Java does not have an initialization, condition, or iteration step?
a) for loop
b) while loop
c) do-while loop
d) Infinite loop
What does the break statement do in a loop in Java?
a) Skips the current iteration and continues with the next iteration
b) Exits the loop and continues with the next statement after the loop
c) Restarts the loop from the beginning
d) Halts the program execution
In Java, which loop executes its body at least once even if the condition is initially false?
a) for loop
b) while loop
c) do-while loop
d) Nested loop
Which loop structure is used when the number of iterations is known beforehand in Java?
a) for loop
b) while loop
c) do-while loop
d) Enhanced for loop
What is the purpose of the continue statement in a loop in Java?
a) Exits the loop
b) Skips the current iteration and jumps to the next iteration
c) Breaks the loop execution
d) Restarts the loop from the beginning
Which loop statement repeats a block of code until a specified condition becomes false?
a) for loop
b) while loop
c) do-while loop
d) Infinite loop
What is the role of the initialization block in a for loop in Java?
a) It defines the loop condition
b) It specifies the increment or decrement value
c) It executes before every iteration
d) It defines the loop counter variable
In a nested loop in Java, which loop's body is executed more frequently?
a) Outer loop
b) Inner loop
c) Both are executed an equal number of times
d) It depends on the conditions
Which loop structure is appropriate for processing elements of an array or a collection in Java?
a) for loop
b) while loop
c) do-while loop
d) Enhanced for loop
What does an infinite loop in Java mean?
a) A loop that never terminates
b) A loop that has no loop body
c) A loop that executes only once
d) A loop that has a fixed number of iterations
Answers:
c) do-while loop
b) Exits the loop and continues with the next statement after the loop
c) do-while loop
a) for loop
b) Skips the current iteration and jumps to the next iteration
c) do-while loop
d) It defines the loop counter variable
b) Inner loop
d) Enhanced for loop
a) A loop that never terminates
No comments:
Post a Comment