Why can't I put " ; " in one line with IF and THEN
Monkey Forums/Monkey Bug Reports/Why can't I put " ; " in one line with IF and THEN
| ||
I like to keep my commands that I include in a separate file in one line, and I use ; (dot and coma) to do it. Everything is okay, but if there is an IF command then it makes it impossible to keep it in one line. Example: Function MouseOverRect:Bool(p1:Int,p2:Int,p3:Int,p4:Int) ; For Local I:Int = 0 To 20 ; If RectsOverLap(Touch[I].X,Touch[I].Y,1,1,p1,p2,p3,p4) Then Return 0 ; EndIf ; Next ; End Function THAT DOESN'T WORK. I tried placing ; instead of then and deleting EndIf as well - same effect. Is it supposed to be that way? |
| ||
Why would you want to do that? o_O Ok anyway, my first thought was that EndIf should be out there because you don't need EndIf at all for single line if statements... |
| ||
Well then it says something about an "unexpected token: Next: |
| ||
Also in your example I would say you are missing a return statement, i.e. what happens if no touches occur ;) |
| ||
The reason you can't do that is because single line if statements can do multiple things on that single line if evaluated as true.If something Then doThis(); andDoThis(); Returnsame as If something doThis() andDoThis() Return EndAnd if you wonder why a EndIf can't be on a single line, it's because it would do something like this... If something EndIf EndI do believe this is a bug, but, eh, whatever. It keeps hard-to-read code like the above away. |
| ||
Great, I've found a bug not worth fixing, yay ^_^ It's sometimes I'd like to keep functions, that there is not much to add to, in one line so I can have them and forget about them |
| ||
I don't want to interfere with your coding guidelines, but if your IDE supports code folding you can just collapse all functions? + still have readable code :) |