Language mavens: Is there a programming with "if then else ENDIF"syntax?

S

Steve Ferg

This is a question for the language mavens that I know hang out here.
It is not Python related, except that recent comparisons of Python to
Google's new Go language brought it to mind.

NOTE that this is *not* a suggestion to change Python. I like Python
just the way it is. I'm just curious about language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then "then" for the condition terminator. You could make it
more PL/I-like by using "do", etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Is there any particular reason why this might be a *bad* language-
design idea?
 
R

Robin Becker

Steve Ferg wrote:
..........
if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then "then" for the condition terminator. You could make it
more PL/I-like by using "do", etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?
........

modern sh seems to use this with "fi" as endif eg

~:
$ if true; then
> echo true
> elif false; then
> echo false
> else
> echo hostile logic
> fi
true
~:
$
 
J

James Harris

This is a question for the language mavens that I know hang out here.
It is not Python related, except that recent comparisons of Python to
Google's new Go language brought it to mind.

NOTE that this is *not* a suggestion to change Python.  I like Python
just the way it is.  I'm just curious about language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

    if <condition> then
        do stuff
    elif <condition> then
        do stuff
    else
        do stuff
    endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then "then" for the condition terminator.  You could make it
more PL/I-like by using "do", etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Is there any particular reason why this might be a *bad* language-
design idea?

There are some. For example, Ada uses similar. See

http://en.wikipedia.org/wiki/Ada_(programming_language)#Control_structures

These other newsgroups may be of interest:

comp.programming
comp.lang.misc

The latter is used by people designing programming languages where you
can find knowledgeable comments aplenty.

James
 
A

Adrian Cherry

ups.com:
This is a question for the language mavens that I know hang
out here. It is not Python related, except that recent
comparisons of Python to Google's new Go language brought it
to mind.

NOTE that this is *not* a suggestion to change Python. I
like Python just the way it is. I'm just curious about
language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse
statements.

I've often thought that a language with this kind of
block-free syntax would be nice and intuitive:

if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using
a colon rather then "then" for the condition terminator.
You could make it more PL/I-like by using "do", etc.

You can write shell scripts using if ... fi, but other than
that I don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Is there any particular reason why this might be a *bad*
language- design idea?

I believe MATLAB has similar if syntax - please correct me if I'm
wrong.

From

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html

"The if function can be used alone or with the else and elseif
functions. When using elseif and/or else within an if statement,
the general form of the statement is"

if expression1
statements1
elseif expression2
statements2
else
statements3
end


Adrian
 
M

MRAB

Steve said:
This is a question for the language mavens that I know hang out here.
It is not Python related, except that recent comparisons of Python to
Google's new Go language brought it to mind.

NOTE that this is *not* a suggestion to change Python. I like Python
just the way it is. I'm just curious about language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then "then" for the condition terminator. You could make it
more PL/I-like by using "do", etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Is there any particular reason why this might be a *bad* language-
design idea?

Ada and Turing have:

if <condition> then
do stuff
elsif <condition> then
do stuff
else
do stuff
end if

Comal has:

if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
end if

Modula-2 has:

if <condition> then
do stuff
elsif <condition> then
do stuff
else
do stuff
end
 
R

Robin Becker

Robin Becker wrote:
........
modern sh seems to use this with "fi" as endif eg

~:
$ if true; then
true
~:
$

I meant to say that since sh uses this construct it cannot be too bad as a
language construct since the world is built with sh and bash and similar.

Of course that's a bad argument since there's more cobol than everything else
put together (allegedly).
 
R

Robin Becker

Robin Becker wrote:
........
modern sh seems to use this with "fi" as endif eg

~:
$ if true; then
true
~:
$

I meant to say that since sh uses this construct it cannot be too bad as a
language construct since the world is built with sh and bash and similar.

Of course that's a bad argument since there's more cobol than everything else
put together (allegedly).
 
N

Nobody

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.
Does anybody know a language with this kind of syntax for
ifThenElseEndif?

BBC BASIC V had if/then/else/endif (it didn't have elif).

"make" has if/else/else/endif (it doesn't have a dedicated elif, but
"else if ..." behaves like elif rather than starting a nested "if").
Is there any particular reason why this might be a *bad* language-
design idea?

Blocks can be useful for other reasons (e.g. limiting variable scope), so
if you already have them, you don't need to provide dedicated blocks
for control constructs.
 
M

MRAB

Nobody said:
BBC BASIC V had if/then/else/endif (it didn't have elif).
I forgot about that one. :-(

I used to do this in order if I wanted to avoid a lot of indentation:

CASE TRUE OF
WHEN <condition>
do something
WHEN <condition>
do something
OTHERWISE
do something
ENDCASE
 
D

Dennis Lee Bieber

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

said:
Does anybody know a language with this kind of syntax for
ifThenElseEndif?
FORTRAN 77 and later

Ada
 
C

Chris Rebert

This is a question for the language mavens that I know hang out here.
It is not Python related, except that recent comparisons of Python to
Google's new Go language brought it to mind.

NOTE that this is *not* a suggestion to change Python.  I like Python
just the way it is.  I'm just curious about language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

   if <condition> then
       do stuff
   elif <condition> then
       do stuff
   else
       do stuff
   endif

Note that you do not need block delimiters.
Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Ruby:

if count > 10
puts "Try again"
elsif tries == 3
puts "You lose"
else
puts "Enter a number"
end

Cheers,
Chris
 
R

r

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

    if <condition> then
        do stuff
    elif <condition> then
        do stuff
    else
        do stuff
    endif

WHY? Python's syntax is by far the most elegant of all, no need to
show the end of a block. Python is the smartest kid on the block. And
are you saying you would rather type "then" instead of ":" and "endif"
instead of "\n"?

No thanks!
 
E

Edward A. Falk

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if <condition> then
do stuff
elif <condition> then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

"then", "else", and "endif" *are* the block delimiters
 
R

Robert Kern

"then", "else", and "endif" *are* the block delimiters

I think he meant that you don't need *extra* block delimiters or generic block
delimiters like {}.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
B

Barry W Brown

This is a question for the language mavens that I know hang out here.
It is not Python related, except that recent comparisons of Python to
Google's new Go language brought it to mind.

NOTE that this is *not* a suggestion to change Python.  I like Python
just the way it is.  I'm just curious about language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

    if <condition> then
        do stuff
    elif <condition> then
        do stuff
    else
        do stuff
    endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then "then" for the condition terminator.  You could make it
more PL/I-like by using "do", etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Is there any particular reason why this might be a *bad* language-
design idea?

Fortran95. You can even label the IF...END IF structure -- handy for
immense blocks.

This is not a criticism of Python (or of Fortran).
 
A

alex23

Steve Ferg said:
Does anybody know a language with this kind of syntax for
ifThenElseEndif?
VBScript.

Is there any particular reason why this might be a *bad* language-
design idea?

VBScript.
 
S

sjm

On Nov 16, 12:54 pm, Steve Ferg <[email protected]>
wrote:
Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Modern-day COBOL:

IF some-condition
do-something
ELSE
do-something-else
END-IF.

The period is also meaningful as a statement terminator in COBOL,
so it's not as clean as one might like.

I, too, like the Python way.

Cheers,
Steve J. Martin
 
N

nn

This is a question for the language mavens that I know hang out here.
It is not Python related, except that recent comparisons of Python to
Google's new Go language brought it to mind.

NOTE that this is *not* a suggestion to change Python.  I like Python
just the way it is.  I'm just curious about language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

    if <condition> then
        do stuff
    elif <condition> then
        do stuff
    else
        do stuff
    endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then "then" for the condition terminator.  You could make it
more PL/I-like by using "do", etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Is there any particular reason why this might be a *bad* language-
design idea?

I personally like the "END X" syntax (not that I would want it for
Python mind you). It makes it easier to read programs backwards.
Foxpro used that syntax form extensively:

http://msdn.microsoft.com/en-us/library/b660264t(VS.80).aspx

DO CASE ... ENDCASE
DO WHILE ... ENDDO
FOR EACH ... ENDFOR
FOR ... ENDFOR
IF ... ENDIF
PRINTJOB ... ENDPRINTJOB
SCAN ... ENDSCAN
TEXT ... ENDTEXT
WITH ... ENDWITH
 
S

steven.oldner

Along the COBOl line is ABAP, the 4gl language from SAP.

If today = 'Mon'.
message 'oh boy'.
elseif today = 'Wed'.
message 'Hump day'.
elseif today = 'Fri'.
message 'TGIF'.
else.
message 'get to work'.
endif.

The period is the statement teminator. Indentation and separte lines
are just to make it readable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top