Break and continue differences and use occasions

Source: Internet
Author: User

Break can leave the program block of the current switch, for, while, and do, and advance to the next statement after the block, which is used primarily to interrupt the next case comparison in switch. It is used primarily to interrupt the current loop execution in for, while, and do.

The Continue function is similar to break, which is used primarily for loops, except that break ends the execution of the block, and continue only ends the statement of the block after it, and jumps back to the beginning of the loop block to continue to the next loop instead of leaving the loop.

1.include<iostream>

using namespace std;

int Main ()

 {

int i=0 ;

while ( i<3)

    {

i++ ;

if ( i==1)

break ;

The value of cout<< "I" is: "<<i< <endl;

    }

&NBSP;        return 0;                                                                               

 }            11> c21> c31> c41> c51> Output Result: (empty)

2.include<iostream>

using namespace std;

int main ()

 {

int i=0;

while ( i<3)

    {

i++ ;

if ( i==1)

continue;

cout< < "I is the value of:" <<i<<endl;

    }

&NBSP;        return 0;                                                                                  Output Result: The value of I is: 2

&NBSP;    }                                                                                                                                          The value of I is: 3



Break and continue differences and use occasions

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.