Skip to content
Sign upLog in
← Back to Community

How to move to a certain line in the program?

Profile icon
Sara3015

If the user inserts a different word that is not "punch" or "defend", I would like the message to pop up and then it should repeat the question at the start (line 17) - "What would Player1 like to do?"

Currently the whole game ends if you misspell a word or don't type in the correct words.

Also I think there might even be a more compact way of doing this - maybe using cases?

(btw I haven't finished the game so there's a different error that comes up stating that I haven't used the variable player1)

image

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
BabyPenguin737
Profile icon
Sara3015
Comments
hotnewtop
Profile icon
Coder100

use a while loop

Profile icon
Coder100
while (true) { if (... user did a good command) { break; } else { ... do nothing/warn ... } } ... more code ...

I think C# has goto statements too, but goto is bad