The code showed IfEqual command used with another command following on the same line. The line after that was indented. It looked as though the proceeding line would be executed if the IfEqual condition was true right along with the command that follows on the same line.
According to the manual:
IfEqual Manual
Here are three test cases with comments in the code that showed expected and unexpected behaviors:Note that command-like If statements allow a command or command-like control flow statement to be written on the same line, but misspelled command names are treated as literal text.
Code: Select all
; Case 1
; Test IfEqual executes the next line when another command follows
; on the same line and the if condition is true.
x := 1
; Since EnvAdd is a command, it should be executed
IfEqual, x, 1, EnvAdd, x, 1
x += 10
MsgBox % "Case 1a: Expecting x to be 12. x is " . x ; x is 12
; ------------------------------------------------------------------------------
; Case 2
; Test IfEqual executes the next line when another command follows
; on the same line and the if condition is false.
x := 1
; Since EnvAdd is a command, it should be executed
IfEqual, x, 2, EnvAdd, x, 1 ; <== condition should fail since x is 1
x += 10 ; <== Does this run if the above condition fails? It seem like it does!
MsgBox % "Case 2: Expecting x to be 1. x is " . x ; x is 11
; ------------------------------------------------------------------------------
; Case 3
; Test IfEqual executes the next line when FUNCTION, not command, follows
; on the same line and the if condition is true.
x := 1
; Since XPlusOne is a funtion, not a command, IfEqual shouldn't execute it
IfEqual, x, 1, XPlusOne(x)
x += 1 ; Why does this not get executed if x is equal to 1? Is it because XPlusOne() isn't a command?
; Expecting the print out to show "Case 2: x is 2"
; BUT it prints out "Case 2: x is 1"
MsgBox % "Case 3: Expecting x to be 2. x is " . x ; x is 1
ChangeY(ByRef x)
{
x += 10
}