It is better to have inBuilt keyword similar to while loop.
For example
In Robot Framework, there is NO WHILE LOOP, DO-WHILE LOOP. It has only FOR LOOP We can perform the DO-WHILE LOOP using FOR LOOP but we cannot control loop on specific condition, Kindly look the following code
:FOR ${i} IN RANGE 999999
/ / #YOUR LOGIC
/ / Exit For Loop If {bool expression}
# Prints out 0,1,2,3,4
count = 0
while count < 5:
print(count)
count += 1
I guess this could be useful in some cases, but most of the time you can use for loops instead of while loops (even your example would be cleaner with a for loop). Also, we highly recommend moving logic like looping to libraries.
Anyway, although I'm not against adding while loop support to Robot Framework's test data, it would be such a huge task that I doubt it will be added in the foreseeable future. I'm also worried that adding it into the already somewhat complex parsing logic would be bad from the code maintenance point of view. My hope is that we get the whole parsing logic rewritten some time in the future and then adding new syntax like this ought to be easier. With the current resources that kind of big rewrites are in the distant future, though, and I would also be much more interested to implement native support for if/else constructs than for while loops.
when I use generator or dynamic list to try to make for loop like while loop function, I found it was static list in RF.
I would like to use for like this but it doesn't work:
li=[0]
for x in li:
li.append(len(li))
.... [do sth]
if ...:
break
or:
def gen():
x=0
while True:
yield x
x+=1
for x in gen():
...
if ...:
break
all won't work
if we can use dynamic list, it will work
I'm closing this issue because while loops certainly won't be implemented in the near future. We got plans to implement IF/ELSE construct and possibly also TRY/EXCEPT, and once they are done while loops can also be considered. At that point this issue can be reopened or new one created.
try and except was supported by decorator in my library.
def deco(func):
def infunc(*args,**kwargs):
try:
res=(true,func())
except:
res=(false,None)
return infunc
then we decorate all other keyword that I can use like this (in my class):
...
@deco
def getmysqlfirst(self, statement):
self.mycur.execute(statement)
return self.mycur.fetchall()[0]
Most helpful comment
I guess this could be useful in some cases, but most of the time you can use for loops instead of while loops (even your example would be cleaner with a for loop). Also, we highly recommend moving logic like looping to libraries.
Anyway, although I'm not against adding while loop support to Robot Framework's test data, it would be such a huge task that I doubt it will be added in the foreseeable future. I'm also worried that adding it into the already somewhat complex parsing logic would be bad from the code maintenance point of view. My hope is that we get the whole parsing logic rewritten some time in the future and then adding new syntax like this ought to be easier. With the current resources that kind of big rewrites are in the distant future, though, and I would also be much more interested to implement native support for if/else constructs than for while loops.