Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.06 KB

break-continue.md

File metadata and controls

47 lines (35 loc) · 1.06 KB

Break

The break is a keyword in One which is used to bring the program control out of the loop. The break statement is used inside loops or switch statement. The break statement breaks the loop one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops. The break statement in One can be used in the following two scenarios:

  • With switch case
  • With loop

Syntax

//loop or switch case
break;

Example

for (int i = 0; i < 10; i++) {
  if (i == 4) {
    break;
  }
  cout << i << "\n";
}

Continue

The continue statement in One language is used to bring the program control to the beginning of the loop. The continue statement skips some lines of code inside the loop and continues with the next iteration. It is mainly used for a condition so that we can skip some code for a particular condition.

Syntax

//loop statements
continue;
//some lines of the code which is to be skipped

Example

for (int i = 0; i < 10; i++) {
  if (i == 4) {
    continue;
  }
  cout << i << "\n";
}