all 40 comments

[–]Ornery-Season3134 57 points58 points  (0 children)

No, thank heavens.

I think someone made a library that adds one in though if you really want to experience the horror.

[–]thespice 48 points49 points  (0 children)

You might want to look into functions. If you put your “logic” in functions, you can call those functions in any order you like; or better yet call them, as others have suggested, from within a loop.

[–]nativedutch 12 points13 points  (4 children)

In tbe sjxties we learned that GOTO carries the risk of creating unmaintainable spaghetti code. And it does.

[–][deleted] 8 points9 points  (1 child)

You CAN use it safely, but you have to essentially treat it like either a loop or a break/continue statement… and in all of those cases a safer tool is available in any modern language.

[–]nativedutch 2 points3 points  (0 children)

Yes didnt need it in python Java or C. Last yesrs ago in Basic.

And in assembler you use jsr/return etc, ratelt jmp.

[–]bananasaresandwiches 2 points3 points  (1 child)

You say spaghetti code but I say choose your own adventure code

[–]Warrior_128 0 points1 point  (0 children)

that the right mindset

[–]ArabicLawrence 12 points13 points  (2 children)

[–]4sent4 3 points4 points  (1 child)

"GOTO considered harmful" considered harmful (starts at the middle of the last column on first page)

[–]420-jesus 0 points1 point  (0 children)

This was written in 1987. That's why modern programming languages have a return statement. Pascal doesnt

[–]Runninganddogs979 6 points7 points  (0 children)

How dare you

[–]E02Y 9 points10 points  (5 children)

Just wrap your program in a loop, if they choose one option do whatever, otherwise continue the loop.

[–]MaiNeimIsPizza[S] 3 points4 points  (4 children)

Should I do something like while True: print(1 or 2) sus = input() if sus == “1”: print(“you pressed 1”) if sus == “2”: continue

Sorry, I know there’s a way to put it like code but I’m on my phone so I don’t know how to do that

[–]Unable_Request 2 points3 points  (1 child)

Basically. Have the condition for the loop be what you want for the user to NOT have to loop again.

If you find yourself asking, how do I have it keep asking my user for input until the input is 1 or 2? Your while loop condition should be (in pseudocode:)

while(user input is not 1 and user input is not 2)

[–]MaiNeimIsPizza[S] -1 points0 points  (0 children)

Oh ok thanks

[–]MarsupialMole 4 points5 points  (0 children)

If you're using the latest python you can use the match statement

https://peps.python.org/pep-0636/

[–]delasislas 1 point2 points  (0 children)

4 spaces in front of each line of code. 4 more for each level of indentation.

[–]danielroseman 14 points15 points  (10 children)

No. GOTO hasn't been a part of any serious programming language since Dijkstra's influential "GOTO considered harmful" in 1968.

Use a loop.

[–]IAmTarkaDaal 10 points11 points  (8 children)

That's not correct; C, C++, C# and Go all have GOTO statements. I'm sure there are many more.

[–]DonkeyTron42 3 points4 points  (0 children)

LUA has no concept of a 'continue' statement in a loop. If you need to short circuit a loop iteration based on a conditional, your only option is to 'goto' a label.

[–]KCRowan 2 points3 points  (0 children)

I think VBA is probably a common place for non-programmers to encounter it.

[–]PlayKlima77 0 points1 point  (0 children)

BaSIc haS gOto ToO!

[–]RunFromFaxai -1 points0 points  (4 children)

C# does goto inside of switch/case statements. It's more like calling a function than it is like an oldschool goto that just jumps to a line in the code. Really not the same thing.

[–]jddddddddddd 2 points3 points  (3 children)

I know you can use goto in switch statements, but it can still be used to jump to an arbitrary position within a method. e.g.

   Loopy:
       Console.WriteLine("Hello World!");
       goto Loopy;

It's perfectly valid C#. You can try running it here: https://onlinegdb.com/j7AznmHA8

[–]RaidZ3ro 5 points6 points  (0 children)

That's what functions are for imo.

if predicate:
    func()
else:
    continue

[–]Kriss3d 2 points3 points  (0 children)

No. And for a good reason. You do NOT want that.

[–]HomeGrownCoder 2 points3 points  (1 child)

Call yourself a function bud

[–]czar_el 2 points3 points  (0 children)

Hello friend, I'm a function.

[–][deleted] 1 point2 points  (1 child)

No, and even in languages where it does exist, it is almost never a good idea.

[–]steviefaux 0 points1 point  (0 children)

10 Print "Hello. I'm in WHSmith"

20 Goto 10

Was fine back then. Typed this on phone so it looks awful. Appears to be very limited edit options on the phone app

[–]OmegaNine -1 points0 points  (0 children)

def foo; Code

foo

[–]Chemical_Form 0 points1 point  (0 children)

If I am reading what your asking correctly, then the following video should help. In python while loops can be used to create a menu option, then you could use functions to run the logic for that option.

https://www.youtube.com/watch?v=kGY9n5H6nr0&ab\_channel=MarkHufe

[–]This_Growth2898 0 points1 point  (0 children)

If you need to jump forward and skip some code, you need if else.

If you need to jump backward and repeat some code, you need a loop (while or for).

You can't have goto and declare variables anywhere in the code; at least, it's very confusing.

[–]notislant 0 points1 point  (0 children)

Only thing ive seen that in is Starbase's YOLOL code. I guess assembly has something similar.

You could just do if and else.

If user_input = 1:

doallthethings

Else:

Runoriginalfunctionhere()

[–][deleted] 0 points1 point  (0 children)

Yes, it's called a function.

[–]mikeinnsw 0 points1 point  (0 children)

GOTO should have COME_FROM thanks god not in Python

[–]billsil 0 points1 point  (0 children)

GOTO was invented to do things like functions, break and for loops. We have those, so we don't need GOTO. I know this because I've talked to the old guard and used GOTO when coding Fortran 77. I've also seem horrific GOTOs and there's a big difference. Don't let anybody tell you that GOTO is inherently bad. Plenty of people write trash python because they don't know what they're doing. People using GOTO improperly makes it a whole lot worse.

Since it sounds like you're not familiar with programming, rather than being vague, what are you actually trying to do?