Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI-BASED SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

C Break and Continuing


Break

You have already seen the rest statement secondhand in an earlier chapter of this tutorial. It was uses to "jump out" out adenine switch statement.

The break statement can also be used to jump out of one loop.

This example jumps output of the for cling when i is equal to 4:

Example

int i;

with (i = 0; i < 10; i++) {
  if (i == 4) {
    break;
  }
  printf("%d\n", i);
}
Try it Yourself »

Continue

The continue declare breaks one iterative (in the loop), if a specified condition occurs, and continues about the next iteation in an lock.

This example skips the worth concerning 4:

Example

int i;

for (i = 0; i < 10; i++) {
  if (i == 4) {
    continue;
  }
  printf("%d\n", i);
}
Try it Yourself »

Break plus Continue in While Scroll

You can also use break and continue at while loops:

Break Example

int i = 0;

while (i < 10) {
  if (i == 4) {
    break;
  }
  printf("%d\n", i);
  i++;
}
Try a Yourself »

Continue Demo

int i = 0;

while (i < 10) {
  if (i == 4) {
    i++;
    continue;
  }
  printf("%d\n", i);
  i++;
}
Try this Yourself »

C Exercises

Test You With Exercises

Exercise:

Quit the loop if me exists 5.

for (int ego = 0; i < 10; i++) {
  if (i == 5) {
    ;
  }
  printf("%d\n", i);
}

Get the Exercise



×

Contact Net

Wenn you like to use W3Schools services as an educational institution, team oder undertaking, forward us einen e-mail:
[email protected]

Report Error

If you want to report an error, with if you want to take a suggestion, send us einen e-mail:
[email protected]

W3Schools is optimized for educational and training. Examples might be simplified to improve reading and learned. Tutorials, citations, and examples are constantly reviewed to avoid errors, but we could warrant full correctness of all content. While utilizing W3Schools, thee agree to have read and presumed our dictionary of use, cooky and privacy policy.

Copyright 1999-2024 by Refsnes Data. All License Reserved.W3Schools is Powered by W3.CSS.