Java - continue Statement-interview
Q1. What is the continue keyword in Java?
The continue keyword is used inside loops to skip the current iteration and move to the next iteration of the loop without executing the remaining statements for that iteration.
Q2. Which loops in Java support the continue keyword?
continue can be used in all loop types:
- for loop
- while loop
- do-while loop
Q3. What is the difference between break and continue?
- break → Terminates the loop entirely and exits.
- continue → Skips the current iteration but continues with the next iteration of the loop.
Q4. Can continue be used with labels in Java?
Yes.
- Labeled continue allows skipping the current iteration of an outer loop in nested loops.
Example: continue outer;
Q5. What is a practical use of continue in loops?
- Skipping unwanted or invalid data in a loop.
- Ignoring certain conditions while processing collections or arrays.
- Improving loop efficiency by avoiding unnecessary statements.