IF ${myvar} versus IF $myvar

I thought I understood the difference between the ${var} syntax and the $var syntax, but I’m still confused by the following:

${myvar}=     Set Variable    False
Log To Console    myvar contains ${myvar}

IF    ${myvar}
    Log To Console    \$\{myvar\} is considered to be True
ELSE
    Log To Console    \$\{myvar\} is considered to be False
END

IF    $myvar
    Log To Console    \$myvar is considered to be True
ELSE
    Log To Console    \$myvar is considered to be False

Output:

myvar contains False
${myvar} is considered to be False
$myvar is considered to be True

I’d like to know why ${myvar} is considered to be False by the IF statement but $myvar is True?

1 Like

That is correct because ${myvar} is the string False so in python "False"

It is not a Boolean value!

When you use ${myvar} the eypression in python is: False

if you do $myvar it is the actual variable that is evaluated. and that is: "False"

And any string in python is True except of an empty one ""

1 Like

Sorry, I’m still confused!

Given
${myvar}= Set Variable False

Using ${myvar} in the IF statement means passing the string ‘False’ to be evaluated in Python.

IF    ${MYVAR}
    Log To Console   Hi
END

is equivalent to this Python code:

if 'False':
  print('Hi')

The Python code will print “Hi”.
The Robot code will not print anything. Why not?

1 Like