while(1){//return from the loop only when the input is zero
printf("\n1: Stack1\n2: Stack2\n0: to return\n");
scanf("%d",&i);
switch(i){
case 1:
printf("1");
break;
case 2:
printf(" 2");
break;
case 0:
printf("Thank you for using the service");
break;
default:
printf("Give a Valid Option");
break;
}//end of switch - case
}//end of while
printf("END");
deepin
0
Newbie Poster
Recommended Answers
Jump to PostAlternatively you could set your condition as the loop condition. A cunstruction I would use would be a do-while setup, as displayed below:
int i; do {//return from the loop only when the input is zero printf("\n1: Stack1\n2: Stack2\n0: to return\n"); scanf("%d",&i); switch(i) { case 1: printf("1"); …
Jump to PostBreaking out of a loop from a
switch
is one of the few places in which agoto
does exactly what is intended without introducing more complexity.But this is typically not the solution; instead, "functionizing" the loop/switch and using a
return
statement from the desired …
All 7 Replies
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
Gonbe
32
Newbie Poster
vaibhav2614
0
Newbie Poster
Dave Sinkula
2,398
long time no c
Team Colleague
mvmalderen
commented:
Clear post, great suggestion(s).
+6
deepin
0
Newbie Poster
jonsca
1,059
Quantitative Phrenologist
Team Colleague
Featured Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.