Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Break and Continue statements in C
#1
break is used to exit the loop prematurely, while continue is used to skip the current iteration and proceed to the next.

for (int i = 1; i <= 10; i++) {
    if (i == 5) {
        break; // Exit the loop when i is 5
    }
    printf("%d ", i);
}
// Output: 1 2 3 4

for (int i = 1; i <= 5; i++) {
    if (i == 3) {
        continue; // Skip the iteration when i is 3
    }
    printf("%d ", i);
}
// Output: 1 2 4 5
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  if-else statements in C Qomplainerz 0 210 07-25-2023, 10:52 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 6 Guest(s)