Welcome
Welcome to unofficialdistros

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

no switch command? no select case? no problem

no switch command? no select case? no problem

Postby figosdev » Fri Mar 17, 2017 2:24 am

solutions are shown in both fig and python.

you want a multiline command which:

* has a clear top and bottom line
* has various if thens
* drops to the bottom and stops checking when a match is found

the solution is a while loop with a break at the end:

Code: Select all
while
    pass

    break
    wend



each conditional should have a break in it too, so that the "switch" is exited when the conditional is true:

Code: Select all
#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/

while
   
    iftrue x
        now "x is true" print
        break
        fig

    ifmore y 7
        now "y is more than 7" print
        break
        fig

    ifequal z p
        now "z is equal to p" print
        break
    else
        now "z is not equal to p" print
        break
        fig

    break
    wend


in python:

Code: Select all
#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/

while 1:
   
    if x:
        print("x is true")
        break
        #fig

    if y > 7:
        print("y is more than 7")
        break
        #fig

    if z == p:
        print("z is equal to p")
        break
    else:
        print("z is not equal to p")
        break
        #fig

    break
    #wend
figosdev
Site Admin
 
Posts: 175
Joined: Sat Sep 03, 2016 2:19 am

Return to Python (programming, etc.)



Who is online

Users browsing this forum: No registered users and 0 guests

cron
suspicion-preferred