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

ElseIf with OR comparison executing incorrectly

$
0
0
I just had to fix a problem where I did a comparison on a variable using OR in an ElseIf statement, and it would fail to match (expected) but still execute anyways. Here is a generic example:

[ autoit ]      
If $value = "Name1" Then ; do Name1 stuff ElseIf $value = "Name2" OR "Name5" Then ; do Name25 stuff ElseIf $value = "Name3" Then ; do Name3 stuff ElseIf $value = "Name4" Then ; do Name4 stuff Else ; show error EndIf

Now, SyntaxCheckProd did not show any validation issues but in practice this code would fail in this condition. If $value matched Name3 or Name4 values, it would execute the "Name25" code even though it should have been skipped. Any times when Name1, Name2 or Name5 matched, then the code would execute properly. I have not tested where Name4 would match. I "fixed" this by putting "Name5" code into its own ElseIf statement, but it makes me wonder why this ended up happening.

And yes, I should probable switch over to using Switch/Case instead but I am just curious.

Viewing all articles
Browse latest Browse all 12506

Trending Articles



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