Home > Backend Development > C#.Net Tutorial > The difference between break and continue when jumping out of a loop

The difference between break and continue when jumping out of a loop

angryTom
Release: 2020-02-08 11:03:45
Original
3511 people have browsed it

The difference between break and continue when jumping out of a loop

The difference between break and continue when jumping out of a loop

● break: Break out of this loop and execute the statements below this loop.

● continue: Terminate this cycle and enter the next cycle.

break example:

#include<stdio.h>

int main()
{
    int num = 0;
    int i = 0;
    for (int i = 0; i < 10; i++)
    {
        if (num == 5)
        {
            break;
            num += 2;  
        }
        num += 1;
    }
    printf("%d\n", num);
    system("pause");
    return 0;
}
Copy after login

The output result is 5.

When num =5, the program jumps out of the loop directly and executes the output statement, so the output is 5.

continueExample:

#include <stdio.h>

int main()
{
    int num = 0;
    int i = 0;
    for (int i = 0; i < 10; i++)
    {
        
        if (num == 5)
        {
            num += 2;
            continue;
        }
        num += 1;
    }
    printf("%d\n", num);
    system("pause");
    return 0;
}
Copy after login

The output result is 11.

Recommended learning: c language video tutorial

The above is the detailed content of The difference between break and continue when jumping out of a loop. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template