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

Discussion in 'Python' started by Steve Ferg, Nov 16, 2009.

  1. Steve Ferg

    Steve Ferg Guest

    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?
    Steve Ferg, Nov 16, 2009
    #1
    1. Advertising

  2. Steve Ferg

    Robin Becker Guest

    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
    ~:
    $

    --
    Robin Becker
    Robin Becker, Nov 16, 2009
    #2
    1. Advertising

  3. Steve Ferg

    James Harris Guest

    On 16 Nov, 16:54, Steve Ferg <> wrote:
    > 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
    James Harris, Nov 16, 2009
    #3
  4. Re: Language mavens: Is there a programming with "if then else ENDIF" syntax?

    Steve Ferg <> wrote in
    news:
    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
    Adrian Cherry, Nov 16, 2009
    #4
  5. Steve Ferg

    MRAB Guest

    Steve Ferg wrote:
    > 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
    MRAB, Nov 16, 2009
    #5
  6. Steve Ferg

    Robin Becker Guest

    Robin Becker wrote:
    ........
    > 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
    > ~:
    > $
    >


    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).
    --
    Robin Becker
    Robin Becker, Nov 16, 2009
    #6
  7. Steve Ferg

    Robin Becker Guest

    Robin Becker wrote:
    ........
    > 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
    > ~:
    > $
    >


    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).
    --
    Robin Becker
    Robin Becker, Nov 16, 2009
    #7
  8. Steve Ferg

    Nobody Guest

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

    On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote:

    > 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.
    Nobody, Nov 16, 2009
    #8
  9. Steve Ferg

    MRAB Guest

    Nobody wrote:
    > On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote:
    >
    >> 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).
    >

    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

    > "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.
    >
    MRAB, Nov 16, 2009
    #9
  10. On Mon, 16 Nov 2009 08:54:28 -0800 (PST), Steve Ferg
    <> declaimed the following in
    gmane.comp.python.general:

    > 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.


    <snip>

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

    FORTRAN 77 and later

    Ada
    --
    Wulfraed Dennis Lee Bieber KD6MOG
    HTTP://wlfraed.home.netcom.com/
    Dennis Lee Bieber, Nov 16, 2009
    #10
  11. Steve Ferg

    Chris Rebert Guest

    On Mon, Nov 16, 2009 at 8:54 AM, Steve Ferg
    <> wrote:
    > 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.

    <snip>
    > 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
    --
    http://blog.rebertia.com
    Chris Rebert, Nov 16, 2009
    #11
  12. Steve Ferg

    r Guest

    On Nov 16, 10:54 am, Steve Ferg <>
    wrote:

    > 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!
    r, Nov 16, 2009
    #12
  13. In article <>,
    Steve Ferg <> wrote:
    >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

    --
    -Ed Falk,
    http://thespamdiaries.blogspot.com/
    Edward A. Falk, Nov 16, 2009
    #13
  14. Steve Ferg

    Robert Kern Guest

    On 2009-11-16 14:40 PM, Edward A. Falk wrote:
    > In article<>,
    > Steve Ferg<> wrote:
    >> 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


    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
    Robert Kern, Nov 16, 2009
    #14
  15. On Nov 16, 10:54 am, Steve Ferg <>
    wrote:
    > 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).
    Barry W Brown, Nov 16, 2009
    #15
  16. Steve Ferg

    alex23 Guest

    Steve Ferg <> wrote:
    > 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.
    alex23, Nov 17, 2009
    #16
  17. On Nov 16, 4:54 pm, Steve Ferg <> wrote:
    > 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.


    GAP uses almost exactly this syntax, but with 'fi' instead of 'endif':

    http://www.gap-system.org/Manuals/doc/htm/ref/CHAP004.htm#SECT016

    Mark
    Mark Dickinson, Nov 17, 2009
    #17
  18. Steve Ferg

    sjm Guest

    On Nov 16, 12:54 pm, Steve Ferg <>
    wrote:
    <snip>
    > 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
    sjm, Nov 17, 2009
    #18
  19. Steve Ferg

    nn Guest

    On Nov 16, 11:54 am, Steve Ferg <>
    wrote:
    > 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
    nn, Nov 17, 2009
    #19
  20. 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.
    steven.oldner, Nov 17, 2009
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Casey Hawthorne
    Replies:
    4
    Views:
    995
    Jarek Zgoda
    Aug 4, 2006
  2. Aahz
    Replies:
    15
    Views:
    435
    david
    Apr 20, 2009
  3. Mensanator
    Replies:
    23
    Views:
    711
    Marco Mariani
    Apr 20, 2009
  4. Hendrik van Rooyen
    Replies:
    7
    Views:
    270
    Mensanator
    Apr 19, 2009
  5. Andrew S. Townley
    Replies:
    0
    Views:
    319
    Andrew S. Townley
    Apr 13, 2009
Loading...

Share This Page