Reputation: 215
val = 12
:FOR ${i} IN RANGE ${val}
Run Keyword If condition1 or condition2 Call_Keyword ${val1} {val2}
Run Keyword If condition3 exit for loop
I am using this snippet test.robot file, but it says as
FOR loop contains no keywords.
I do not understand. what's wrong in this ?
Upvotes: 0
Views: 13996
Reputation: 20067
You forgot to indent the keywords in the loop, e.g. to mark them as "the looped over block".
As explained in the user guide,
The keywords used in the for loop are on the following rows and they must be indented one cell to the right. When using the plain text format, the indented cells must be escaped with a backslash, ...
So in your case, as of 2017, it should be:
:FOR ${i} IN RANGE ${val}
\ Run Keyword If condition1 or condition2 Call_Keyword ${val1} {val2}
\ Run Keyword If condition3 exit for loop
In the newer version of the framework this syntax is deprecated, and uses a block ended with the END
keyword:
FOR ${i} IN RANGE ${val}
Run Keyword If condition1 or condition2 Call_Keyword ${val1} {val2}
Run Keyword If condition3 exit for loop
END
Upvotes: 2
Reputation: 541
According to the user guide, a correct for-in-range loop in Robot Framework 3.2+ would be the following:
FOR ${i} IN RANGE ${val}
Run Keyword If condition1 or condition2 Call_Keyword ${val1} {val2}
Run Keyword If condition3 exit for loop
END
Upvotes: 0
Reputation: 42
You forgot to indent the keywords in the loop, e.g. to mark them as "the looped over block".
As explained in the user guide,
The keywords used in the for loop are on the following rows and they must be indented one cell to the right. When using the plain text format, the indented cells must be escaped with a backslash, ...
So in your case, it should be:
${startValue} Set Variable 0 # initial value
${endvalue} Set Variable 12 # End Value
${Step} Set Variable 1 # step value
:FOR ${i} IN RANGE ${startvalue} ${endvalue} step=${step}
\ Run Keyword If condition1 or condition2 Call_Keyword ${val1} {val2}
\ Run Keyword If condition3 exit for loop
Upvotes: 0