Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I found a way to achieve the effect of WHILE keyword #3235

Closed
rainydew opened this issue Jul 10, 2019 · 2 comments
Closed

I found a way to achieve the effect of WHILE keyword #3235

rainydew opened this issue Jul 10, 2019 · 2 comments

Comments

@rainydew
Copy link

rainydew commented Jul 10, 2019

@gaurav294
just modify this file robot\running\steprunner.py, near line 33
edit this function to

    def run_steps(self, steps):
        errors = []

        cursor = 0  # the index to execute
        keywords = [ str(step).lower() for step in steps ]
        
        while cursor < len(steps):
            try:
                step = steps[cursor]
                if str(step).lower() == "reloop":
                    assert "exit for loop if" in keywords or "exit for loop" in keywords,\
                        "both for loop and exit condition are needed"
                    cursor = 0
                    continue
                cursor += 1
                self.run_step(step)
            except ExecutionPassed as exception:
                ......

Then the RELOOP "keyword" can jump to the first line immediately but it won't carry the next element of the range.

So we can use it like this

*** Test Cases ***
Example_Case
    ${j}    set variable  ${0}
    :for    ${n}    in range    ${1}
    \       ${j}    set variable  ${${j}+1}
    \       log many    ${j}
    \       exit for loop if      ${j}==${1000}
    \       reloop
    log many        done    ${j}

this means

j=0
while True:
    j=j+1
    print j
    if j==1000: break
print "done", j

but a bit ugly
any other good modifies?

#2721

@pekkaklarck
Copy link
Member

This is interesting but not something that will be directly added to RF. Native WHILE loop support may be added after we got IF/ELSE and TRY/EXCEPT done.

@95rade
Copy link

95rade commented Apr 2, 2020

Wondering if any progress has been made on implementing IF/ELSE and TRY/EXCEPT ?
tnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants