if var1 <> 2 then
result:= true;
var1:= 3;
else
result:= false;
var1:= 5;
end;
=========================
Much better
Even better than "if .. {} else {}".
How about combined "elif/elseif" ? Me think it's highly demanded.
<mse00000@gmail.com> 17 ноября 2013 г., 22:46
Do you have a real example where "elseif" is much better than nested "if"s
or "case"?
Martin
------------------------------------------------------------------------------
Marcos Douglas
<md@delfire.net> 17 ноября 2013 г., 23:17
IMHO I think you didn't understand what Martin want to do in MSE. He
wants a language more orthogonal.
"
So, if you can use if-else-if construction, why he will implement a
if-eleif construction that do the same?
Martin, do you know Lua language? For me it is the simpler language
that exists... of course is a interpreted language, but you can catch
some ideas for MSElang.
Ivanko B
<ivankob4mse2@gmail.com> 17 ноября 2013 г., 23:37
Nested "else if" starts another hierarchy level. Very inconvineient & messy.
"Case" is for integer switches currently.
Ivanko B
<ivankob4mse2@gmail.com> 17 ноября 2013 г., 23:44
So, if you can use if-else-if construction, why he will implement a
if-eleif construction that do the same?
========================
Personanly me often get messed with "else-if"
Martin Schreiber
<mse00000@gmail.com> 18 ноября 2013 г., 0:01
> Nested "else if" starts another hierarchy level. Very inconvineient &
> messy. "Case" is for integer switches currently.
>
Can you show real code?
Martin Schreiber
<mse00000@gmail.com> 18 ноября 2013 г., 0:10
> Martin, do you know Lua language? For me it is the simpler language
> that exists... of course is a interpreted language, but you can catch
> some ideas for MSElang.
>
Yes, there are some similarities.
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 0:47
Can you show real code?
=================
if a = 0 then
writeln ('a=0');
else
if a = 1 then
writeln ('a=1');
end
else
if a = 2 then
writeln ('a=2');
end
else
writeln ('a=else');
end;
end;
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 0:48
With "elif":
==================
if a = 0 then
writeln ('a=0');
elif a = 1 then
writeln ('a=1');
elif a = 2 then
writeln ('a=2');
Martin Schreiber
That is from a project of you? I mean't code from Podpiska project for
example. I would write above code as:
"
if a = 0 then
writeln ('a=0');
else
if a = 1 then
writeln ('a=1');
else
if a = 2 then
writeln ('a=2');
else
writeln ('a=else');
end;
end;
end;
"
I don't think
"
if a = 0 then
writeln ('a=0');
elseif a = 1 then
writeln ('a=1');
elseif a = 2 then
writeln ('a=2');
else
writeln ('a=else');
end;
"
is much better. In my opinion it is worse because there is no indention
between "if" and "end;" and it hides nesting levels.
Martin
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 12:36
Here "a=else" & "a = 2" depend on the decision for "a=1" which in turn
depends on the one for "a=0". So we have 3 hirerarchy levels. To see
the effect better me add some more padding:
------------------------------
if a = 0 then
writeln ('a=0');
else
if a = 1 then
writeln ('a=1');
else
if a = 2 then
writeln ('a=2');
else
writeln ('a=else');
end;
end;
end;
--------------------------
but really they're LOGICALLY on same hierarcy as "a=0".
PS: Martin, this code is atrociuos ! And with the new (BEGINless)
syntax it can't be simplified even for single command per-branch.
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 12:43
http://www.cise.ufl.edu/~mssz/Pascal-CG ... loops.html-------------------------------------------------
4.2. PASCAL Selection Structures.
The PASCAL language provides IF or BLOCK-IF constructs, where the
latter is a variation of the IF statement, as discussed in Section
3.1. We define these statements as follows:
IF..THEN..ELSE statement:
IF..THEN..ELSEIF..THEN..ELSE (Block-IF) statement:
Purpose: The Block-IF statement provides a mechanism for decision
based on multiple logical predicates. This can be useful for grouping
data items into prespecified categories.
Syntax: IF predicate1 THEN actions-if-predicate1-is-true
ELSEIF predicate2 THEN
actions-if-predicate2-is-true
:
ELSEIF predicateN THEN
actions-if-predicateN-is-true
ELSE actions-if-predicates-are-false ; , where
actions-if-predicate-is-true are one or more PASCAL statements
actions-if-predicate-is-false are one or more PASCAL statements
PASCAL also supports nested decision structures, in which an IF
statement contains other IF statements in its list of executable
statements. This allows the programmer to specify decisions based on
concepts or criteria that are hierarchically structured.
Martin Schreiber
<mse00000@gmail.com> 18 ноября 2013 г., 13:06
> Here "a=else" & "a = 2" depend on the decision for "a=1" which in turn
> depends on the one for "a=0". So we have 3 hirerarchy levels. To see
> the effect better me add some more padding:
> ------------------------------
> if a = 0 then
> writeln ('a=0');
> else
> if a = 1 then
> writeln ('a=1');
> else
> if a = 2 then
> writeln ('a=2');
> else
> writeln ('a=else');
> end;
> end;
> end;
> --------------------------
> but really they're LOGICALLY on same hierarcy as "a=0".
>
Then use case:
"
case a of
0:
writeln ('a=0');
1:
writeln ('a=1');
2:
writeln ('a=2');
else
writeln ('a=else');
end;
"
> PS: Martin, this code is atrociuos ! And with the new (BEGINless)
> syntax it can't be simplified even for single command per-branch.
>
I suggest to use a single space for indention only then you get a "end
diagonal" at end, please see the screenshot in previous mail. What about my
objection:
"
In my opinion it is worse because there is no indention
between "if" and "end;" and it hides nesting levels.
"?
Martin
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 13:22
Then use case:
=================
It's INTEGER switch only, AFAIK. And compare expressions may
differentiate - the "case" can't provide that
and it hides nesting levels.
==================
In the example no levels but the top one are expected.
Martin Schreiber
<mse00000@gmail.com> 18 ноября 2013 г., 13:51
> Then use case:
> =================
> It's INTEGER switch only, AFAIK. And compare expressions may
> differentiate - the "case" can't provide that
>
In FPC and possibly in MSElang strings work too.
> and it hides nesting levels.
> ==================
> In the example no levels but the top one are expected.
>
But the levels *are* nested so one should see that they are nested.
"
if a > 3 then
writeln('a>3');
elseif a > 5 then
writeln('a>5');
elseif a >10 then
writeln('a>10');
end;
"
mostlikely does not what the inventor intended.
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 14:27
strings
==================
Not strings but chars (convertable to integer). And "case" doesn't
allow changing/extending comprare expressions for conditions.
mostlikely does not what the inventor intended.
==============
First matched branch will be executed
The same as "if else" but
with much shorted and more readable syntax.
"if else" is designed for cases where structure hierarchy is important.
So we have two approached each for different purpose - for advanced
"case" and structured hierarchy.
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 14:28
*are* nested
=======================
They're nested not more than branches of CASE are nested
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 15:17
Since CASE is a partial case (a convinience syntax entention) of ELIF
then rather CASE should be removed than ELIF
Michael Schnell
<mschnell@lumino.de> 18 ноября 2013 г., 15:58
> Do you have a real example where "elseif" is much better than nested "if"s
I use such indentation:
if a=b then begin
..x := y;
.end else if c = d then begin
..z := w;
.end else if f = g then begin
..s := t;
end;
with that "an "elseif keyword is not necessary at all and it corresponds
nicely to "case:
case a of
.1:
..x := y;
.2:
..z := w;
.3:
..s := t;
end;
In C I do this with braces instead of begin/end and adding the braces in
the "case" (here "switch") block for each alternative, as C has "fall
through" switch cases.
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 16:01
think this is a very clear and handsome syntax.
===============
as long as FPC has ":=" which definetely misses its brothers
case of string.
===============
And no CASE for (strangely discriminated) float/numeric types
And
"FOR .. BY <step>" for them as well.
Ivanko B
<ivankob4mse2@gmail.com> 18 ноября 2013 г., 16:10
I use such indentation:
=======================
Only the cunny indentation allows to have the code be readable. It's
an workaround
as C has "fall through" switch cases.
=======================
Not so bad, BTW.