Doubt command in Python

Asked

Viewed 157 times

-2

I am migrating from batch programming to Python, in batch there was the "goto" command, which basically created a sub-area within the command:

goto EXEMPLO
pause

:EXEMPLO
pause

So, when the command arrives in "EXAMPLE" it jumps to the line ":EXAMPLE", is it possible to do this in Python? (I use 3.6)

  • This example does nothing useful. If you give an example where it is useful we can show how to do in Python. This is just do nothing.

  • The idea is quite simple, let’s say that you have a choice, where the user who is running the code can choose between 1 and 2, if it is 1 goes to a certain area of the command, if it is 2 goes to another, then returns to the beginning and can make the choice again.

  • So put this example in the question. If you want to know one thing and ask another, you will get bad answers.

1 answer

1

No. In Python you should use repetition structures and conditional structures to control the flow of your code.

To run lines of code if a drive is true, you do the following:

minhaVariavel = 5

if minhaVariavel == 5:
    print('O valor eh 5')
else:
    print('O valor nao eh 5')

To repeatedly execute a chunk of code while a condition is true, you do the following:

minhaVariavel = 0

while minhaVariavel < 5:
    print('O valor eh ' + str(minhaVariavel))
    minhaVariavel += 1

And there are many other control structures.

The official language website has a tutorial on this, you can access here: https://docs.python.org/3/tutorial/controlflow.html

Don’t forget to indent your code!

  • Ah, I understood, what a pity, thank you also, it was very helpful!

  • Good @Dariusdacosta. If my answer solved your doubt, do not forget to mark it as correct.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.