Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there any alter to goto in python?

Version: Python 3.7

for obj in group_obj.objects:
            bpy.ops.ed.undo_push()
        --> move_rotate(obj, T, T_0)
        |
        |   if check_if_cross_wall(obj):
        |       bpy.ops.ed.undo()
        ________from there


            count += 1
            accessableArea(obj)
        

Here is my code, My target is to check if the condition satisfied, if True, it will reverse the operation and goto first line directly. I think goto is the most suitable way to do this, but I just know goto in C or C++, python do not contain this. Is there any other way to alter it?

My code logic is:
move & rotate object, then check if it cross the wall, if True, reverse the operation, then move & rotate again and check if it cross the wall. If False, it will save current state and go to next object

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No, there is no "goto" in Python. To accomplish the sort of jump you describe, you can just use a loop though with a continue statement to move back to the start of the loop and break to exit the loop, like this:

for obj in group_obj.objects:
    bpy.ops.ed.undo_push()
    
    while True:
        move_rotate(obj, T, T_0)
        
        # as long as this is true, it will keep
        # moving back to the start of the loop
        if check_if_cross_wall(obj):
            bpy.ops.ed.undo()
            continue
            
        # Exit the loop
        break

    count += 1
    accessableArea(obj)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading