http://entrian.com/goto/
#Example 1:breaking out from a deeply nested loop: fromGotoImportGoto, Label forIinchRange (1, 10): forJinchRange (1, 20): forKinchRange (1, 30): PrintI, J, KifK = = 3: Goto. Endlabel. EndPrint "finished\n"#Example 2:restarting a loop: fromGotoImportGoto, Labellabel. Start forIinchRange (1, 4): PrintIifi = = 2: Try: Output=messageexceptNameerror:Print "oops-forgot to define ' message '! Start again."message="Hello World"Goto. StartPrintOutput"\ n"#Example 3:cleaning up after something fails: fromGotoImportGoto, Label#Imagine that these is real worker functions.defSetUp ():Print "setUp"defDofirsttask ():Print1;returnTruedefDosecondtask ():Print2;returnTruedefDothirdtask ():Print3;returnFalse#This one pretends to fail.defDofourthtask ():Print4;returnTruedefCleanUp ():Print "cleanUp"#This prints "setUp, 1, 2, 3, cleanUp"-no "4" because Dothirdtask fails.defBigFunction1 (): SetUp ()if notdofirsttask (): Goto. Cleanupif notdosecondtask (): Goto. Cleanupif notdothirdtask (): Goto. Cleanupif notdofourthtask (): Goto. Cleanup label. Cleanup Cleanup () BigFunction1 ()Print "BigFunction1 done\n"#Example 4:using Comefrom to let the cleanup code take control itself. fromGotoImportcomefrom, LabeldefBigFunction2 (): SetUp ()if notDofirsttask (): label. Failedif notDosecondtask (): label. Failedif notDothirdtask (): label. Failedif notDofourthtask (): label. Failed Comefrom. Failed cleanUp () BigFunction2 ( )Print "BigFunction2 done\n"#Example 5:using A computed goto: fromGotoImportGoto, Labellabel. Getinputi= Raw_input ("Enter either ' a ', ' B ' or ' C ', or any other letter to quit:")ifIinch('a','b','C'): Goto*IElse: Goto. Quitlabel. APrint "You typed ' a '"Goto. Getinputlabel. bPrint "You typed ' B '"Goto. Getinputlabel. CPrint "You typed ' C '"Goto. Getinputlabel. QuitPrint "finished\n"#Example 6:what happens when a label is missing: fromGotoImportGoto, Labellabel. Realgoto. Unreal#raises a Missinglabelerror exception.
Python goto Package