Continue and Break

code 1:

#include<stdio.h>
int main(){
int i;
for(i=10;i<20;i++)
{
if(i%2==0)
    continue;
if(i>16)
    break;
printf("%d\n",i);
}

return 0;
}

output:
11
13
15

Continue Easily Explained:

#include<stdio.h>
int main(){

int count;
for(count=1;count<=100;count++){
    if(count%2==0)
        continue; //continue mane erpore ja ase setar porer ongsjo r print hobe na borong increment ta add hoye jabe direct
    printf("Count = %d\n",count);
}

return 0;
}

Output:

Count = 1
Count = 3
Count = 5
Count = 7
Count = 9
Count = 11
Count = 13
Count = 15
Count = 17
Count = 19
Count = 21
Count = 23
Count = 25
Count = 27
Count = 29
Count = 31
Count = 33
Count = 35
Count = 37
Count = 39
Count = 41
Count = 43
Count = 45
Count = 47
Count = 49
Count = 51
Count = 53
Count = 55
Count = 57
Count = 59
Count = 61
Count = 63
Count = 65
Count = 67
Count = 69
Count = 71
Count = 73
Count = 75
Count = 77
Count = 79
Count = 81
Count = 83
Count = 85
Count = 87
Count = 89
Count = 91
Count = 93
Count = 95
Count = 97
Count = 99

Good Vid for Easy Explanation:

code 2:

#include<stdio.h>
int main(){
int i;
for(i=10;i<20;i++)
{
if(i%2==0)
    continue;
printf("%d\n",i);
if(i>16)
    break;
}
return 0;
}

output:
11
13
15
17
Easily Explained Code:

#include<stdio.h>
int main()
{
    int i,count;
    char ch;
    for(count=1; count<=100; count++)
    {
        printf("count = %d\n",count);
        printf("Do you want to continue:?\n");
        scanf(" %c",&ch);
        if(ch=='y' || ch=='Y'){
            break;
        }
    }
    printf("Terminated at %d\n",count);


    return 0;
}

Output:

count = 1
Do you want to continue:?
t
count = 2
Do you want to continue:?
r
count = 3
Do you want to continue:?
w
count = 4
Do you want to continue:?
y
Terminated at 4

Theory for this easy explanation:

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.