Use of break in C

Source: Internet
Author: User
Break statements are typically used in loop statements and switch statements. When break is used in switch statements, the program can jump out of a switch and execute a switch statement, and if there is no break statement, the execution starts from the place where the condition is met (that is, the case that matches the expression in the switch (expression) bracket). Until the switch structure is finished. When the break statement is used in an do-while, for, and while Loop statement, the program terminates the loop. Instead of executing the statements that follow the loop, the break statement is always associated with the IF statement. That is, it jumps out of the loop when the condition is met. Example: Main () {int I=0;char c;while (1)///Set loop */{c= ' \ n ';/* variable assigns initial value */while (c!=13&&c!=27)//keyboard receives character until press ENTER or ESC key */{c=getch ();p rintf ("%c\n", c);} if (c==27) break; /* Determine if the ESC key exits the Loop */i++;p rintf ("the No. Is%d\n ", i);} printf ("the End");} Note : 1. The break statement has no effect on if-else conditional statements. 2. In a multilayer loop, a break statement jumps only one layer outward.

Use of break in C

Related Article

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.