Python Forum
Using "goto" to jump to lines ?!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using "goto" to jump to lines ?!
#1
Hi guys, there I just finished my program, except small problem these are two subroutines.



So I would like to create a question which program would you choose cod or dec

I therefore use if cod
Else ...

But especially how you go from line 1 to 45
Or from line 45 to 1  Think

So i imagine something like that : 

#LOGICIEL DE CRYPTAGE ET DE DÉCRYPTAGE#

print("Voulez vous coder ou décrypter ?")
text = input("taper code pour coder et dec pour décrypter")
if "code" 
return line 9
else:
return line 48
Of course this example is wrong but it sums up my ideas Wink
Reply
#2
"return" is not a "goto".

text = input("taper code pour coder et dec pour décrypter")
if text=="code" 
     # Whatever is needed to encode
else:
     # Whatever is needed to decode
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
Ok but they said me for if error syntax :(
Reply
#4
Hi guys, I finally finished my program except that I want to turn them into a unique program.

I had planned to use goto to move from a line to the line we want but why it does not work:




print("Voulez vous coder ou décrypter ?")
text = input("taper code pour coder et dec pour décrypter")

if text =="code":

   gotoCODAGE;

if text=="dec":

   gotoDECRYPTAGE;

else:

   gotoERREUR;



CODAGE;

DECRYPTAGE;

ERREUR;

 **cry** 
Reply
#5
Just a few notes for you to get answers faster:

Please do not keep making new threads for essentially the same question. I have merged them for you now.

Please use meaningful titles, not "little problem", "BIG PROBLEM", I have renamed the thread for you now.

There is no "goto" functionality in python. Where did you learn the idea? Which python tutorial do you use?

You may want to continue your tutorial until you learn about python functions. This will solve your problem.
Reply
#6
But how can I return at the line i want :(

please answer quickly...

I use python in a site vers 3.3
Reply
#7
(Jan-28-2017, 07:30 PM)LOLO Wrote: But how can I return at the line i want :(

please answer quickly...

I use python in a site vers 3.3

Python is not Fortran or Basic. You don't return to a line... Computer languages have removed this capability in the 80s for good reasons. If you want to execute some code when a condition is true, then you have an if statement followed by a "block" that contains the code to execute if this condition is true. Good programming style recommends that where there are many statements (big block),  these statements are put in a function, and the block just becomes a "call" to the function.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020