Java Control Statements
Java Control Statements - Important Points
1. | Which control flow statement is used to exit from a loop? |
---|
A. continue
B. break
C. return
D. exit
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The break statement is used to exit from a loop before its normal termination.
2. | What is the difference between a while loop and a do-while loop in Java? |
---|
A. A while loop runs at least once, while a do-while loop may not run at all.
B. A while loop always runs exactly once, while a do-while loop may run more than once.
C. A while loop tests its condition at the beginning of the loop, while a do-while loop tests its condition at the end of the loop.
D. A while loop is used for iterating over arrays, while a do-while loop is used for iterating over collections.
View Answer Discuss Work SpaceAnswer: option c
Explanation:
3. | Which of the following is not a valid loop control statement in Java? |
---|
A. continue
B. break
C. return
D. goto
View Answer Discuss Work SpaceAnswer: option d
Explanation:
4. | Which control flow statement is used to skip the remaining statements in the current iteration of a loop and move on to the next iteration? |
---|
A. continue
B. break
C. return
D. skip
View Answer Discuss Work SpaceAnswer: option a
Explanation:
5. | Which of the following statements is true about nested loops in Java? |
---|
A. Nested loops can only be used with for loops, not with while or do-while loops.
B. A break statement inside a nested loop terminates only the innermost loop.
C. A continue statement inside a nested loop skips only the innermost loop.
D. Nested loops are never used in real-world programming.
View Answer Discuss Work SpaceAnswer: option b
Explanation: