FAQ  •  Register  •  Login

is THEN necessary?

<<

slenkar

Posts: 282

Joined: Sun Feb 13, 2011 3:33 am

Location: Kentucky US, used to be Birmingham UK

Post Sat Aug 18, 2012 10:50 pm

is THEN necessary?

every time I do an IF statement I always forget THEN, can it be made optional?
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Aug 19, 2012 9:14 am

Re: is THEN necessary?

THEN is used both for compatibility's sake with Sinclair and FreeBASIC and as "region" separator in the parsing phase.
The common structure is:
  Code:
IF <condition> THEN <sentence> END IF

Here "<condition>" is something very fussy. It could be just "1", or something more complex like 3+A* Cos(pi) / 180.0.
Look at this example:
  Code:
IF a a = a + 1: END IF

Makes the code less readable and could introduce some ambiguity in the parser. The THEN token marks the finish of the <expression> region. C does not uses the "THEN", but requires mondatory parenthesis around <expression> to treat this ambiguity.
Anyway, I've tested it and the THEN can be made optional... but again this goes away from BASIC. :| where legibility matters

What about the rest of users? What do you think?

Update: The best way to tackle this problem is to use a good IDE which will warns you of the missing THEN (this is a complex task) or even generate the IF THEN template for you.
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Aug 25, 2012 1:10 am

Re: is THEN necessary?

Could parse the ambiguity by saying "THEN" or newline?

IF a (then)
a=a+1
end if

So an alternate if construction is:

IF <condition>
list of statements
END IF

Would that work?
<<

slenkar

Posts: 282

Joined: Sun Feb 13, 2011 3:33 am

Location: Kentucky US, used to be Birmingham UK

Post Sat Aug 25, 2012 2:51 am

Re: is THEN necessary?

yeah that would be good
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Aug 25, 2012 9:33 am

Re: is THEN necessary?

britlion wrote:Could parse the ambiguity by saying "THEN" or newline?

Not needed, surprisingly, I've managed to make the THEN optional quite easily. But this goes away from BASIC...
Anyway, It will be uploaded soon.
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Sun Aug 26, 2012 8:54 pm

Re: is THEN necessary?

Oh, that is great!
I always forget it too because it is not needed in PureBasic.
The syntax is:
IF a:a+1:ENDIF
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Aug 26, 2012 8:57 pm

Re: is THEN necessary?

LCD wrote:Oh, that is great!
I always forget it too because it is not needed in PureBasic.
The syntax is:
IF a:a+1:ENDIF

This is already uploaded in the RELEASE 1.2.9. Now let's go for 1.3.0 (sigh!).

Return to Wishlist

Who is online

Users browsing this forum: No registered users and 0 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO