// break statements are used to bring the program out of the loop.
// usually break statements are used inside loops & switch statements.
// continue statement is used to skip some portion of the loop and
the code will jump to the next iteration.
//It is so important when we want to skip some lines of code for
a particular condition.
#include <stdio.h>
int main()
{
char name[20];
int age;
printf ("enter your name: \n");
scanf ("%s", &name);
printf ("hello %s, how are you?\n");
printf ("hope you will be fine.\n");
for (int i = 1; i < 11; i++)
{
// senario_1 there is no obstacle in the path of code.
// senario_2 there is continue statement.
(continue ke bad wala code terminate hoga.)
// senario_3 there is break statement.
(break ke bad ka complete loop hi terminate ho jayega.)
printf ("%d\n", i);
break;
printf ("enter you age: \n");
scanf ("%d", &age);
}
return 0;
}
different output in different scenario:_
scenario:_1 {no obstacle}
(jab tak loop condition false nhi ho gayi tab tak loop chala.)
PS E:\c programming> cd "e:\c programming\" ; if ($?)
{ gcc breakcont.c -o breakcont } ; if ($?) { .\breakcont }
enter your name:
lalu
hello lalu, how are you?
hope you will be fine.
1
enter you age:
23
2
enter you age:
29
3
enter you age:
29
4
enter you age:
0
5
enter you age:
0
6
enter you age:
9
7
8
8
enter you age:
7
9
enter you age:
6
10
enter you age:
5
scenario:_2{continue statement}(continue statement se pahle wala pura
loop code chala)
# yaha what is your age wala code execute nhi hua because usse pahle
continue statement tha and for loop ke ander ka complete
i wala code chala.
PS E:\c programming> cd "e:\c programming\" ; if ($?)
{ gcc breakcont.c -o breakcont } ; if ($?) { .\breakcont }
enter your name:
kalu
hello kalu, how are you?
1
2
3
4
5
6
7
8
9
10
scenario:_3 {break statement}(jaha par break statement aa gaya vahi se
complete loop terminate ho gaya.)
#yaha loop only loop ke initial output 1 ko print karke hi terminate ho
gaya.
PS E:\c programming> cd "e:\c programming\" ; if ($?)
{ gcc breakcont.c -o breakcont } ; if ($?) { .\breakcont }
enter your name:
bhalu
hello bhalu, how are you?
hope you will be fine.
1
No comments:
Post a Comment
here we are to help you.you can watch videos and get information about :- (1) scientific facts (2) education (3) gaming (4) music (5) lyrics (6) cartoons and many more.So keep watching keep learning, thank you.