+ 4

Do you know about the the keyword "goto" which was used in Turbo C++.

Guys I thought of making a game in C++ but I am struck at one point . Is there any alternate keyword for the keyword goto , which was accessed by the <conio.h> library . If you know that please tell me . If you due didn't got the question here is a simple example for that : - .....some code P : cout<<"\n Enter the number "; switch(choice) { case 1: cout<<"That's number 1"; break; case 2: cout<<"That's number 2"; break; ....... default : goto P; break; } ....some code Plz tell me what can replace goto

14th Aug 2017, 11:58 AM
RZK 022
RZK 022 - avatar
12 Antworten
+ 6
AFAIK, goto can still be used without the need to include <conio.h>.
14th Aug 2017, 2:58 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Bc that's how the truly loop of computer work.and it is optimized loop.But the strongly reason is "I like Assembly >.>" Anyway~ @Atikrant Negi why you want to replace goto???? As if User input is another number so you will make it jump to P label....
14th Aug 2017, 12:40 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 4
It is better to use a loop of some kind to accomplish what you want in this particular instance.
14th Aug 2017, 12:16 PM
jay
jay - avatar
+ 3
Ehhhh that code is valid....do you mind to type what do you want to do again please?
14th Aug 2017, 12:09 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 3
Ahem, goto is a .... never use word. Never use it ! It comes from Assembly which works only with something similar. It is meant to go to a label. Label can be written that way : a_label:; //statement It is strictly discourage to use it as it can bring unwanted behavior easily, it can render the code unclear, even unreadable
14th Aug 2017, 12:13 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
I think goto statement faster and better than to use readymade c loop (I like assembly :P)
14th Aug 2017, 12:30 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 3
@Very_Hard(java & c++ & c# & rust & (AllHard)) actually that's just an example , I want the code to do something else , but it is the same as it is used in the example . When the input is not valid I want it to jump to the first sentence . But I think I found a solution :- I am using a function instead of it , I think it will work efficiently .
14th Aug 2017, 12:57 PM
RZK 022
RZK 022 - avatar
+ 2
that's valid in Turbo c++
14th Aug 2017, 12:10 PM
RZK 022
RZK 022 - avatar
+ 2
I can't bring a loop there , I know how to do this using while loop but that can't be used here . I this case there is a switch case statement and the main skeleton is outside it .
14th Aug 2017, 12:17 PM
RZK 022
RZK 022 - avatar
+ 2
@All hard, what makes you say that ? Edit : no offence, I am really interested ^^
14th Aug 2017, 12:32 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar