Page 1 of 2
If ... Then
Posted: Mon Jun 17, 2019 12:26 pm
by diceman
One petty thing I'm missing in PureBasic, now don't laugh, is the "If ... Then" Statement.
When there's just one line of consequence, "If ... Then" looks cleaner, plus you'll get another tool to structure your code.
is clunky.
Re: If ... Then
Posted: Mon Jun 17, 2019 12:29 pm
by BarryG
Re: If ... Then
Posted: Mon Jun 17, 2019 12:31 pm
by RSBasic
Why not with : ?
Or you create a macro:
Re: If ... Then
Posted: Mon Jun 17, 2019 12:34 pm
by diceman
RSBasic wrote:Why not with : ?
Or you create a macro:
But you'd still need the Endif at the end. And that's what makes it clunky (imho).
But I like the trick in Barry's link quite a bit:
Code: Select all
If/Then macro by PB. Usage: If <condition> Then (<code>)
Macro Then (code)
: code : EndIf
EndMacro
age=Val(InputRequester("If/Then example","How old are you?",""))
If age<21 Then (MessageRequester("Result","No beer drinking for you!"))
If age>20 Then (MessageRequester("Result","It's your shout for a beer!"))
That really works? Looks to good to be true! I mean, I've worked with Macros before, but not to that extent ...
I gotta try that when I'm at home!
Re: If ... Then
Posted: Mon Jun 17, 2019 12:51 pm
by oreopa
If...Then is a hangover from basic with line numbers IMO. Most (or at least C64 basic V2) couldnt do multiline statements, so THEN was a kinda logical thing (remember "ON A GOTO 100,200,300...."?

Thats how I used to handle multiple cases.)
These days I don't see the use of it... it seems like verbosity for verbosities sake, but I'm glad you kinda got the solution anyway

Macros FTW!
Re: If ... Then
Posted: Mon Jun 17, 2019 3:42 pm
by Little John
diceman wrote:One petty thing I'm missing in PureBasic, now don't laugh, is the "If ... Then" Statement.
When there's just one line of consequence, "If ... Then" looks cleaner, plus you'll get another tool to structure your code.
Code where
If sometimes is followed by
Then, and sometimes is not followed by
Then, does
not look cleaner to me than the code which is currently valid in PureBasic, where
If is never followed by
Then.
-1 from me.
Re: If ... Then
Posted: Mon Jun 17, 2019 5:02 pm
by diceman
Thanks again for pointing me to the location where I got my solution from. It might not seem like a big thing, but you just made me the 2nd happy man in the world (No.1 happiest man is the guy married to Kate Upton).
You see, I'm just a humble hobbyist who has never never coded with anything else than BASIC-Languages, and I'm so used to using "Then" with single line consequences, I immediately noticed it's absence when switching from Blitz to Pure (even though I'm in love with all the rest PB has to offer). Might be an OCD-Thing, even, can't rule that out for sure.
Here's my final solution (the capital letters make it stick out as a command, and the underscore seperates it visually from the Statement):
Code: Select all
Macro THEN_(code)
: code : EndIf
EndMacro
An appropriate Thank You:

Re: If ... Then
Posted: Tue Jun 18, 2019 1:06 am
by BarryG
You're not related to Kwai chang caine by any chance? LOL!

Re: If ... Then
Posted: Tue Jun 18, 2019 3:38 am
by Fangbeast
He can't be. Kwai would have posted an animated clip of the Hoff in his speedos that none of us could ever unsee!
Re: If ... Then
Posted: Tue Jun 18, 2019 7:10 am
by RSBasic
Re: If ... Then
Posted: Tue Jun 18, 2019 7:37 am
by HanPBF
When I see such a statement in code (Basic, Pascal, etc.):
I first immediately change it to
Code: Select all
;pseudo code
if a = b then
c = 1
endif
and second kick the coder!
procedure.s iifs(check.b, whenTrue.s, whenFalse.s)
if check
procedureReturn whenTrue
else
procedureReturn whenFalse
endif
endProcedure
define a.s = iifs(bool(1 = 0), "true", "false")
Re: If ... Then
Posted: Tue Jun 18, 2019 10:09 pm
by diceman
Btw. ...
I'm back to If / Else / Endif ...
You guys are right, "Then" is unneccessary and turns beautiful, readable code into noisy garbage. I learned that the hard way.
I was so sure that I was missing something, but when I finally got it, it turned out to be a major disappointment and not at all how I remembered it.
It's been such a long time since I last did something with another language than PB, and in the meantime, it seems like PureBasic has turned me into a better human being.
Yet, this thread was not in vain, since I learned something new about Macros, how to further use and abuse them.
Thanks a lot, guys!
Re: If ... Then
Posted: Wed Jun 19, 2019 12:24 am
by Tenaja
I used to use macros to make pb more like what I was accustomed to, back when I first started. I quit doing it before a year had passed. By the third year, I looked at some of my original code and wondered what the heck I was thinking. I look back and know I should have just embraced the language as it was for what it was.
Re: If ... Then
Posted: Wed Jun 19, 2019 12:01 pm
by blueb
Tenaja wrote:...I should have just embraced the language as it was for what it was.
Amen brother... Amen.

Re: If ... Then
Posted: Wed Jun 19, 2019 1:19 pm
by Marc56us
Tenaja wrote:I used to use macros to make pb more like what I was accustomed to, back when I first started. I quit doing it before a year had passed. By the third year, I looked at some of my original code and wondered what the heck I was thinking. I look back and know I should have just embraced the language as it was for what it was.
That's also why I even avoid creating my own libs and modules for
small basic functions and prefer to use the PB model system or keyboard automatic typer.
Code sometimes less readable at the time but much more years later.
And EXE is not less or more sized
