If behavior

Monkey Forums/Monkey Bug Reports/If behavior

bram(Posted 2013) [#1]
I'm using this code:

		If (False) If (True) Print "test 1"
		If (True) If (True) Print "test 2"	

		Print "one"
		Print "two"

I'm expecting to see "test2, one, two", but instead I see just "two".
Easy fixable by placing End If's in there, but I found it confusing behavior.
The double If is something I use mainly if the second condition contains an object that needs to be verified before usage, such as this:
if (selection <> null) if (selection.parent = currentItem) selection.display();
I'm using MacOS, HTML5 and the Monkey 'Love' edition (version 69)


Goodlookinguy(Posted 2013) [#2]
In the languages monkey outputs to, if the first expression fails they don't evaluate the latter expression.

So
If blah <> Null And blah.blah = "something" Print "blah"

Will not crash your game if blah is null.


bram(Posted 2013) [#3]
Maybe it is just a habit, coming from Blitz3D. Still, the above is a bug, right?


Goodlookinguy(Posted 2013) [#4]
I'm not entirely sure if it's a bug or 'by design'. Will have to wait for Mark to chime in on this one.


marksibly(Posted 2013) [#5]
Weirdly, Monkey appears to be appending the 2nd If line to the first - try inserting a newline between the 2. Will have a look at this.

Using 'And' fixes it too.


Samah(Posted 2013) [#6]
What language are you using that doesn't support short-circuited boolean expressions? o_O


bram(Posted 2013) [#7]
It is not the language, it is me. It is a very very old habit, that I've never updated over the years.