The basic course of C language (iii) input and output functions and control flow statements (18)

Source: Internet
Author: User
Tags exit printf
1.3.4break, continue and GOTO statements
1.3.4.1break statement
Break statements are usually used in circular statements and in switch statements. When the break is used in switch statement switches, the program can jump out of switch and execute a switch statement, and if there is no break statement, it becomes a dead loop and cannot exit. The use of the break in the switch has been encountered in the example described earlier in the switch statement, which is no longer an example.
When a break statement is used in a do-while, for, and while Loop statement, the program terminates the loop and executes the statement following the loop, and usually the break statement is always associated with the IF statement. That is, when the conditions are met, they jump out of circulation.
Example 19:
Main ()
{
inti=0;
Charc;
while (1)/* Set Loop * *
{
C= ' "; /* Variable Assignment initial value * *
while (c!=13&&c!=27)//keyboard receives character until press ENTER or ESC key * *
{
C=getch ();
printf ("%c\n", c);
}
if (c==27)
Break /* To determine if the ESC key to exit the cycle * *
i++;
printf ("theno.is%d\n", I);
}
printf ("theend");
}
Attention:
The 1.break statement does not work for if-else conditional statements.
2. In a multi-layer cycle, a break statement jumps only one layer.
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.