Multi-pattern IF, ELSE IF, ELSE control

Hello Robot community,

reference: Conditional IF / ELSE IF / ELSE execution in Robot Framework | Robocorp documentation

I’m having difficulty with what I think is a basic programming concept. I’m trying to write if and else if control loops with multiple conditions. For example,

IF “abc” in ${HOST} or “def” in ${HOST} or “hij” in ${HOST}
. . . do something
ELSE IF IF “tuv” in ${HOST} or “xyz” in ${HOST}
. . . do something else
ELSE
. . . do nothing and end

when I attempt this type of control loop, I get an error about a keyword not being next. I have two questions:

1 - Is this type of multi-condition If, else if looping possible in Robot?
2 - If it is, is there a better document which provides better instruction on what I might be doing wrong?

Confused!

Hi

That documentation ref you have been using is on point.

The snippet you shared holds two IF IF on the ELSE IF and you also have no END after the end of the block
image

The in is to check if in an object, but as the format is not correct and will be tripping over here first it has likely not to have got that point yet for any errors if any, if you are unsure of the type, you can debug with:

${type}=    Evaluate     type($variable)
${type}=    Evaluate     type($variable).__name__

It’s probably worth getting the format correct for the IF first; you do mention “looping” though whereas the snippet shared and a IF / ELSE IF / ELSE are conditionally checks not looping.

I hope that helps

2 Likes