Use of local in statements

Monkey Forums/Monkey Programming/Use of local in statements

Shagwana(Posted 2015) [#1]
I cant help but think that the following should be valid but alas is not...

Select local iChar:int = GetChar()
	Default
	Print iChar
End Select


The scope of iChar would be to that of the select statement only.


tiresius(Posted 2015) [#2]
Can you do that within an IF () ?


nullterm(Posted 2015) [#3]
"Can you do that within an IF () ?"

.

If you could, reminds me alot of Swift, and is one of the cooler parts of the language once you get your head wrapped around optionals and unwrapping...



It becomes helpful for casting...


.

It may seem trivial, but once you start coding more and more in Swift then your code gets ALOT simpler/cleaner. ObjC iOS code can get pretty lengthy for one statement.



... becomes...



Not to mention, the fact it's wrapped by a "if let" means it's safer, in case it doesn't exist or it's a different type.

.

So, if you could, something like this in Monkey X land...