08-19-2024, 07:30 PM
I think Terry your nested IF statements would only perform the next test IF the last one was true. Otherwise, as you point out, IF any of the conditions test False no other conditions are tested.
I'm thinking if your code did include Else in the nesting then I think all the conditions would be tested...I think...
IF R1.right >= R2.left THEN ' check for overlapping coordinates
Else
IF R1.left <= R2.right THEN
Else
IF R1.bottom >= R2.top THEN
Else
IF R1.top <= R2.bottom THEN ' all checks passed, must be a collision
RectCollide% = -1 ' return that a collision was detected (TRUE)
END IF
END IF
END IF
END IF
IF R1.right >= R2.left THEN ' check for overlapping coordinates
ElseIF R1.left <= R2.right THEN
ElseIF R1.bottom >= R2.top THEN
ElseIF R1.top <= R2.bottom THEN ' all checks passed, must be a collision
RectCollide% = -1 ' return that a collision was detected (TRUE)
END IF
Both Else and ElseIF would test each condition, without the Else or ElseIF conditions are tested until a False is incurred....I thinks that's correct. Your code would short circuit the IF run and that could save a lot of time in processing
I'm thinking if your code did include Else in the nesting then I think all the conditions would be tested...I think...
IF R1.right >= R2.left THEN ' check for overlapping coordinates
Else
IF R1.left <= R2.right THEN
Else
IF R1.bottom >= R2.top THEN
Else
IF R1.top <= R2.bottom THEN ' all checks passed, must be a collision
RectCollide% = -1 ' return that a collision was detected (TRUE)
END IF
END IF
END IF
END IF
IF R1.right >= R2.left THEN ' check for overlapping coordinates
ElseIF R1.left <= R2.right THEN
ElseIF R1.bottom >= R2.top THEN
ElseIF R1.top <= R2.bottom THEN ' all checks passed, must be a collision
RectCollide% = -1 ' return that a collision was detected (TRUE)
END IF
Both Else and ElseIF would test each condition, without the Else or ElseIF conditions are tested until a False is incurred....I thinks that's correct. Your code would short circuit the IF run and that could save a lot of time in processing