how to return to the begining of switch statement

I just wrote some code about the switch statement.

bool exit;
while(!exit){
int selection;
cin>>selection;

switch(selection){
case 1:
cout<<"1:The Suburbs"<<endl;
break;
case 2:
cout<<"2:Recovery"<<endl;
break;
case 3:
cout<<"3:Need You Now"<<endl;
break;
cout<<"4:The Fame Monster"<<endl;
break;
case 5:
cout<<"5:Teenage Dream"<<endl;
break;
case 0:
exit = true;
break;
}
}

My question is how can i go back to the begining of switch statement is the my input is 0. My code seems doesn't works at that point.

thanks for helping..
if you set exit = true; then !exit will be false, so the while will terminate
Notice that exit is not initialized the first time you reach the while.

Please use [code][/code] tags
thanks. but i got another question

in know how can i go back to the beginning of switch statement now. But still don't know how can i go back to the previous switch statement.

For example
int main(){

Collection c;
Album a;
Song s;
cout<<"Hello, World!n";

cout<<"nPlease Enter a number for a Mode"<<endl;
cout<<" 1- Collection Moden 2- Album Moden 3- Song Moden 4- Song Selection Moden 5- Album Selection Moden"<<endl;
int selection;
cin>>selection;

switch(selection){
case 1:
c.printCollectionMode();
break;
case 2:
a.printAlbumMode();
break;
case 3:
s.printSongMode();
break;
case 4:
s.SonSelectionMode();
break;
case 5:
a.AlbumSelectionMode();
break;

return 0;
}

this is my Main function. for example, if i enter 5, it will execute the AlbumSelectionMode. but How can i go back to the main function after i get into the AlbumSelectionMode
Use a loop as you did before

Again, use [code][/code] tags
Topic archived. No new replies allowed.