Search code examples
c++cgotobasic

How to avoid GOTO in C++


I have read that GOTO is bad, but how do I avoid it? I don't know how to program without GOTO. In BASIC I used GOTO for everything. What should I use instead in C and C++?

I used GOTO in BASIC like this:

MainLoop:
INPUT string$   
IF string$ = "game" THEN   
GOTO game
ENDIF

Solution

  • Usually loops like for, while and do while and functions have more or less disposed the need of using GOTO. Learn about using those and after a few examples you won't think about goto anymore. :)