Re: if 'also' else statment

Discussion in 'C Programming' started by Nobody, Jan 10, 2010.

  1. Nobody

    Nobody Guest

    On Fri, 08 Jan 2010 11:41:41 +0000, Paul wrote:

    > I sometimes think it would be nice if c had an 'also' statement,
    > which meant that 'if a preceeding condition was true, do this as well'.
    >
    > This might save some untidy work-around, or much worse, copy-
    > pasting. Let me know if you have a nice neat alternative.
    >
    > Here's an example of reading a book on weekends, but not weekdays.
    > Naturally, there could be many more things done on a weekend.
    >
    > P.
    >
    > if (Day == Saturday)
    > {
    > WalkInPark();
    > }
    > else if (Day == Sunday)
    > {
    > AttendChurch();
    > }
    > also
    > {
    > ReadABook();
    > }
    > else
    > {
    > GoToWork();
    > }


    Can you re-write that in a way which reflects how C interprets it?

    I.e. starting with:

    if (Day == Saturday)
    {
    WalkInPark();
    }
    else
    if (Day == Sunday)
    {
    AttendChurch();
    }

    At this point, is the "also" associated with the outer "if" or the inner
    "if"?

    Note that C doesn't have an "else if" statement. The "else" clause can
    contain any statement; this can be an "if" statement, or something else.
    Even if it *is* an "if" statement, it doesn't get treated any differently
    because it's an "if" statement or because it's within an "else" clause.
     
    Nobody, Jan 10, 2010
    #1
    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. Ron Adam

    "also" to balance "else" ?

    Ron Adam, Jun 14, 2005, in forum: Python
    Replies:
    27
    Views:
    788
    Tim Roberts
    Jun 17, 2005
  2. Replies:
    25
    Views:
    687
    MonkeeSage
    Oct 1, 2006
  3. kj
    Replies:
    15
    Views:
    579
    Lawrence D'Oliveiro
    May 23, 2009
  4. William McNicol

    Re: if 'also' else statment

    William McNicol, Jan 8, 2010, in forum: C Programming
    Replies:
    2
    Views:
    351
  5. TonyMc

    Re: if 'also' else statment

    TonyMc, Jan 8, 2010, in forum: C Programming
    Replies:
    1
    Views:
    324
    Stefan Ram
    Jan 8, 2010
Loading...

Share This Page