Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Unexpected behavior of = equals operator conditionals

$
0
0

AutoIt documentation of operations states, for the '=' operator,

 

= Tests if two values are equal.  e.g. If $var= 5 Then    (true if $var equals 5). Case insensitive when used with strings.

 

However, I have found that when the value to compare to is 0, all string values compare as equal to 0.

For example,

If("Foo" = 0) Then MsgBox(1, "Result", "Apparently, Foo = 0")

Also true for >= and <=

 

This behavior does not occur with the '==' operator.

Local $a="Foo", $b=0, $res="" If("Foo" = 0) Then $res&="Apparently Foo = 0"&@CRLF If ($a = $b) Then $res&="Apparently "&$a&" = "&$b&@CRLF If ($a == $b) Then $res&="Apparently "&$a&" == "&$b&@CRLF If ($a <= $b) Then $res&="Apparently "&$a&" <= "&$b&@CRLF If ($a >= $b) Then $res&="Apparently "&$a&" >= "&$b&@CRLF If ($a < $b) Then $res&="Apparently "&$a&" < "&$b&@CRLF If ($a > $b) Then $res&="Apparently "&$a&" > "&$b&@CRLF $b=1 If ($a = $b) Then $res&="Apparently "&$a&" = "&$b&@CRLF If ($a == $b) Then $res&="Apparently "&$a&" == "&$b&@CRLF MsgBox(1, "Results", $res)

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>