I'm sure there are more elegant solutions to this problem, but here's an example I thought of
bool exitloop = false;
switch(ch1)
{
case 1 :{
while(1) {
cout<<" Directory Selection"<<endl;
cout<<" 1. Computing Science "<<endl;
cout<<" Enter your choice : ";
cin>>ch2;
switch(ch2){
case 1 : break; //out of inner switch
case 4 :exitloop = true; break; //out of inner switch
}
if(exitloop)
break; //out of while
}
break; //out of outer switch
}
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
This doesn't preclude that. In your outer one you exit from while via the return statement. This one, the break will only exit out one layer.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
You are correct. I think the OP had that in error. What was suggested was return or break not both.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581