Goto for python

Source: Internet
Author: User
Http://entrian.com/goto/
LookSource codeThe trace is modified for all functions, and then the set function is executed when an exception occurs.
# Install the trace function, including all preceding frames.
SYS. settrace (_ trace)
Frame = SYS. _ getframe (). f_back
While frame:
Frame. f_trace = _ trace
Frame = frame. f_back
Change the day to see how to analyze each row in the traceCodeOf!

# Example 1: Breaking out from a deeply nested loop:
From goto import Goto, label
For I in range (1, 10 ):
For J in range (1, 20 ):
For k in range (1, 30 ):
Print I, J, K
If K = 3:
Goto. End
Label. End
Print "finished \ n"


# Example 2: restarting a loop:
From goto import Goto, label
Label. Start
For I in range (1, 4 ):
Print I
If I = 2:
Try:
Output = message
Failed t nameerror:
Print "oops-Forgot to define 'message '! Start again ."
Message = "Hello World"
Goto. Start
Print Output, "\ n"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.