IF with THEN to continue in a single line

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

IF with THEN to continue in a single line

Post by uwekel »

Hi,

it is hard to find, maybe it has been posted before.

Does it make sense to use the THEN keyword for IF conditions, just to continue it on a single line?

Example:

Code: Select all

If Condition = #True Then Value = 1 [Else Value = 0]
instead of

Code: Select all

If Condition = #True 
  Value=1
[Else
  Value = 0]
Endif
Regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: IF with THEN to continue in a single line

Post by Dude »

uwekel wrote:it is hard to find, maybe it has been posted before.
There was a macro over 10 years ago that does it: http://www.purebasic.fr/english/viewtop ... 12&t=20619 ;)
User avatar
mk-soft
Always Here
Always Here
Posts: 6209
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: IF with THEN to continue in a single line

Post by mk-soft »

Perhaps over macro...

Code: Select all

Macro Then_
  : 
EndMacro

Macro Else_
  : 
EndMacro

Macro EndIf_
  : EndIf
EndMacro

a = 10
If a > 10 Then_ a = 0 Else_ b = a EndIf_
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: IF with THEN to continue in a single line

Post by HanPBF »

That's easy answered.

Never ever use if statement on a single line...
Further editing can lead to confusion.

Worse is done in Perl 6:
$x = 5 if $y == 3;
$z++ unless $x + $y > 8;


Regards
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: IF with THEN to continue in a single line

Post by HanPBF »

Pascal is even worse!

Code: Select all

if a=b then begin
  c := 1;
end else begin
  d := 2;
end;

if a=b then
  c := 1;
else
  d := 2;
Both are equal; but due to the unnecessary verbosity in defining blocks, it encourages one statement branches of if or else.
In Pascal it's easy to write not understandable if-structures; and I have seen many of those!

Thanks to PB the unneeded 'then' has gone and begin of block and end of block are good documented.

Code: Select all

with endWith procedure endProcedure if endIf
Post Reply