C_continue and break

Source: Internet
Author: User

Now more and more found themselves before the white school, are almost graduating, but even the most basic C language is forgotten clean! Hurry up and fill it up!!

In a nutshell, break jumps out of the current loop body (or switch), and then executes the statement below the loop, and continue ends the loop, does not execute the statement that is not yet executed under the loop body, and then makes the next loop judgment.

The professional understanding of the book is that the break statement can be exited from the inner loop or the switch statement. The continue statement can only appear in the for, while, do loops. (Feel like you don't understand, or see examples)

#include <stdio.h> int main (void) {    int flag=0;    for (int j=0; J <2; J + +) {       if (j==0) {          switch (j) {case             0:             continue;          }          flag=1;       }    }    printf ("flag:%d\n", flag);}

Output flag:0 Replace the continue with a break; the output flag:1

#include <stdio.h> void Main () {    int flag = 0;    int j = 0;    for (J=0; J <2; J + +) {       if (j==0) {          if (j==0) {             continue;          }          flag=1;       }    }    printf ("flag:%d\n", flag);}

Without a switch, break only works on the loop body, so the result of break and Continue is flag:0

Another switch example, will not believe and forget!

#include <stdio.h>#include<string.h>intMain () {Chari;  for(i=0;i<5; i++){                 Switch(i) { Case 0: printf ("i=%d\n", i); Break;  Case 1: printf ("i=%d\n", i); Break;  Case 2: printf ("i=%d\n", i);Continue;p rintf ("ok\n");  Case 3: printf ("i=%d\n", i); Break; default: printf ("errp\n"); } printf ("lalala\n");      } getch (); }

The Continue and Lalala in the results are not output, and the break is output.

C_continue and break

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.