Search code examples
stringoperatorsautoit

'If string not equal' doesn't work the way I expect in AutoIt


I wrote this code in AutoIt (v3.3.8.1):

$x = 'dog'
if not $x = 'hello' Then
   ConsoleWrite("fish")
Else
   ConsoleWrite("world")
EndIf

Don't you think the output should be "fish"? But instead it says "world". What's up?


Solution

  • It's because of operator precedence. Contrary to other languages, like BASIC and Perl, in AutoIt not has higher precedence than equality. Change the code to

    if not ($x = 'hello') then
    

    or

    if $x <> 'hello' then