C case control statement क्या होते है?
case control statement in C
तो चलिये शुरू करते है W4 learn in Hindi के साथ,
case control statement in C
1) C break statement:
Break Statement एक loop control statement है जिसका उपयोग loop को समाप्त करने के लिए किया जाता है। जैसे ही एक loop के भीतर से Break Statement का सामना किया जाता है, loop immediately वहीं रुक जाती हैं और loop के तुरंत बाद पहले statement में loop से returns को control करती हैं।
Syntax:
break;
Flow chart of break statement:
1) Example of break:
#include <stdio.h>
int main()
{
int i;
for(i=0;i<10;i++)
{
if(i==6)
{
printf("\nComing out of for loop when i = 6");
break;
}
printf("%d ",i);
}
return 0;
}
Output:
0 1 2 3 4 5
Coming out of for loop when i = 6
Coming out of for loop when i = 6
2) Example break statement with while loop:
#include<stdio.h>
void main ()
{
int i = 0;
while(1)
{
printf("%d ",i);
i++;
if(i == 10)
break;
}
printf("out of while loop");
}
Output:
0 1 2 3 4 5 6 7 8 9 out of while loop
2) C continue statement:
Continue Statement Program के loops के condition के हिसाब से बीचवाले statements को skip कर देता है और बादवाले statement को execute करता है |
Syntax:
//loop statements
continue;
//some lines of the code which is to be skipped
Flow chart of continue statement:
Flow chart of continue statement:
1) Example for continue Statement:
#include <stdio.h>
int main(){
int i;
for(i=0;i<10;i++)
{
if(i==7)
{
printf("Number %d is skipped.\n",i);
continue;
}
printf("%d\n",i);
}
return 0;
}
Output:
0
1
2
3
4
5
6
Number 7 is skipped.
8
9
1
2
3
4
5
6
Number 7 is skipped.
8
9
2) C continue statement with inner loop:
#include<stdio.h>
int main(){
int i=5,j=5; //initializing a local variable
for(i=5;i<=7;i++){
for(j=5;j<=7;j++){
if(i==6 && j==6){
continue; //will continue loop of j only
}
printf("%d %d\n",i,j);
}
} //end of for loop
return 0;
}
int main(){
int i=5,j=5; //initializing a local variable
for(i=5;i<=7;i++){
for(j=5;j<=7;j++){
if(i==6 && j==6){
continue; //will continue loop of j only
}
printf("%d %d\n",i,j);
}
} //end of for loop
return 0;
}
Output:
5 5
5 6
5 7
6 5
6 7
7 5
7 6
7 7
3) C goto Statement:
Go to ये C Programming का statement है | इसमें labels का use किया जाता है |
Types of Goto Statement:
1) Forward
2) Backward
जब goto statement कुछ statement को छोड़कर उसके अगले statement को execute करता है , उसे Forward goto statement कहते है और किसी पिछले या execute हुए statement को फिरसे execute करने के लिए अपने पिछले label पर जाता है , उसे Backward goto statement कहते है |
Syntax for Forward and Backward goto Statement:
Syntax for Forward
goto label ;
statement ;
-----------
label ;
Syntax for Backward
label ;
statement ;
-----------
goto label ;
1) Example to print table for goto statement:
#include <stdio.h>
int main()
{
int num,i=1;
printf("Enter the number whose table you want to print?");
scanf("%d",&num);
table:
printf("%d x %d = %d\n",num,i,num*i);
i++;
if(i<=10)
goto table;
return 0;
return 0;
}
Output:
Enter the number whose table you want to print?5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
2) Example of ATM for goto statement:
#include<iostream>
using namespace std;
int main()
{
int n, actualpin=1234, count=0;
atm:cout<<"Enter pin number of your ATM: ";
cin>>n;
while(actualpin!=n && count<2)
{
count++;
goto atm;
}
if(actualpin==n)
{
cout<<"Your ATM has been opened";
}
else
{
cout<<"Your ATM has been locked";
}
return 0;
}
Output:
Enter pin number of your ATM: 4567
Enter pin number of your ATM: 8547
Enter pin number of your ATM: 1234
Your ATM has been opened
Comments