Page 1 of 1
IF with THEN to continue in a single line
Posted: Sun Jul 10, 2016 12:51 pm
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
Re: IF with THEN to continue in a single line
Posted: Sun Jul 10, 2016 1:01 pm
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 
Re: IF with THEN to continue in a single line
Posted: Sun Jul 10, 2016 1:04 pm
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_
Re: IF with THEN to continue in a single line
Posted: Sun Jul 10, 2016 1:42 pm
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
Re: IF with THEN to continue in a single line
Posted: Sun Jul 10, 2016 1:48 pm
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