O2 multi-line "if" handling - it is magic!

Started by Ed Davis, February 08, 2025, 01:44:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ed Davis

O2 is so cool! 

In O2, I can write:
if condition1 then: statment1
elseif condition2 then: statement2
else: statement3
end if

In _every_ other Basic I've tried (QB, QB64, FreeBasic, QBJS, SmallBasic, YABasic, BAM) I have to write:
if 0 then
elseif condition1 then: statement1
elseif condition2 then: statement2
else: statement3
end if
In order to distinguish a single-line "if" from a multi-line "if".

So how does O2 recognize that "if condition1 then: statement1" is the start of a multi-line "if" statement and not a single-line "if" statement? 

p.s. Still making good use of the "select" without a condition statement!  Thanks for adding that!

Charles Pegge

#1
Hi Ed,

It's the colon that breaks the logical line and causes the multiline interpretation.

'then' is only required for single liners. Otherwise it is ignored.

So this works too: :)

int a,b,c
a=5
b=5
if a<b     : c=1
elseif a=b : c=2
elseif a>b : c=3
endif
print c

Yes, I remeber the case tweak. This performs the same way:

int a,b,c
a=5
b=5
select a
case a<b : c=1
case a=b : c=2
case a>b : c=3
end select
print c