0

Python - Goto? Loops?

I understand there’s no Goto in Python. How do you make the code go back to a certain point. EG: Type in command: ‘list’ (Prints a list) >>> Why I want to do is make the code then go back to the top where it says “type in command” and I can others commands in eg ‘help’ or stuff. I have the commands all coded already.

23rd Oct 2018, 8:40 PM
Plurgie
Plurgie - avatar
2 Answers
+ 1
This is an example of a while loop: X = 5 While x == 5: Input("write a command: ") #so while x is equal to 5 the code will keep referring to the indented section again and again #ps. You will have to replace the apostraphes because my ones are different from what they should be #pps. Check the indentation, they might be wrong, if they are just add or remove spaces
23rd Oct 2018, 9:06 PM
Rohan
+ 1
Also, functions play a big role. To jump between places or to execute code more than once, you call a function from the 'mainstream', or all your code is in functions that call each other.
23rd Oct 2018, 10:27 PM
HonFu
HonFu - avatar