Continue Statement In C Programming Language


In this video tutorial lets learn more about the working of continue statement or continue keyword in C programming language.

Related Read:
Nested For Loop In C Programming Language

Video Tutorial: Continue Statement In C Programming Language


[youtube https://www.youtube.com/watch?v=P1tNHbymJm4]

YouTube Link: https://www.youtube.com/watch?v=P1tNHbymJm4 [Watch the Video In Full Screen.]


Source Code: Continue Statement In C Programming Language : For Loop

#include<stdio.h>

int main()
{
    int i;

    for(i = 1; i <= 5; i++)
    {
        if(i == 3)
            continue;

        printf("%d Apple\n", i);
    }

    return 0;
}

Output:
1 Apple
2 Apple
4 Apple
5 Apple

In above C program we introduce continue keyword when i is equal to 3. So whatever the instructions / statements present after the keyword continue will be skipped and the control will be transferred to the next iteration of the for loop.

Source Code: Continue Statement In C Programming Language : Nested For Loop

#include<stdio.h>

int main()
{
    int i, j;

    for(i = 1; i <= 5; i++)
    {
        printf("%d Apple\n", i);

        for(j = 1; j <= 3; j++)
        {
            if(j == 2)
                continue;

            printf("\t%d Oracle\n", j);
        }

    }

    return 0;
}

Output:

1 Apple
        1 Oracle
        3 Oracle
2 Apple
        1 Oracle
        3 Oracle
3 Apple
        1 Oracle
        3 Oracle
4 Apple
        1 Oracle
        3 Oracle
5 Apple
        1 Oracle
        3 Oracle

In above C program, inside inner for loop we’ve continue keyword when j value is equal to 2. So once the keyword continue is encountered, control directly switches to or transfers to the next iteration of the for loop, skipping all the statements after the keyword continue.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *