ITP

BSc IT - Structure Programming Methodology - Java

Explain break and Continue.

In : BSc IT Subject : Structure Programming Methodology - Java

The break statement is used to immediately exit a loop  (like for, while, or do-while) or a switch statement. As soon as break is encountered, the program stops the loop and continues with the next part of the code. 
Example: 

for (int i = 1; i <= 5; i++) {
    if (i == 3) {
        break;  // Stop the loop when i is 3
    }
    System.out.println(i);

The continue statement is used to skip the current iteration  of a loop and move to the next one. It doesn't stop the whole loop — just the current round. 
Example: 

for (int i = 1; i <= 5; i++) {
    if (i == 3) {
        continue;  // Skip when i is 3
    }
    System.out.print

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap