Re: if 'also' else statment

Discussion in 'C Programming' started by TonyMc, Jan 8, 2010.

  1. TonyMc

    TonyMc Guest

    "Paul" <-> writes:

    > 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();
    > }


    See if you can get your church to meet in the park. Even better, if the
    park provides seating and sufficient light for reading (which, I guess
    would be a prerequisite for holding church services there), your
    conditional expression becomes trivial. If the provisions of the C
    language are not a good fit to your lifestyle, it is probably simpler to
    change your lifestyle than to introduce new keywords into C.

    Tony
    TonyMc, Jan 8, 2010
    #1
    1. Advertising

  2. TonyMc

    Stefan Ram Guest

    TonyMc <> writes:
    >"Paul" <-> writes:
    >> if (Day == Saturday)
    >> {
    >> WalkInPark();
    >> }
    >> else if (Day == Sunday)
    >> {
    >> AttendChurch();
    >> }
    >> also
    >> {
    >> ReadABook();
    >> }
    >> else
    >> {
    >> GoToWork();
    >> }


    Sorry for indirect quoting, but I missed the OP:

    if( day == SATURDAY ) { walk(); we = 1; }
    else if( day == SUNDAY ) { attend(); we = 1; }
    else { work(); we = 0; }
    if( we ) { read(); }
    Stefan Ram, Jan 8, 2010
    #2
    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:
    763
    Tim Roberts
    Jun 17, 2005
  2. Replies:
    25
    Views:
    651
    MonkeeSage
    Oct 1, 2006
  3. kj
    Replies:
    15
    Views:
    540
    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:
    337
  5. Nobody

    Re: if 'also' else statment

    Nobody, Jan 10, 2010, in forum: C Programming
    Replies:
    0
    Views:
    388
    Nobody
    Jan 10, 2010
Loading...

Share This Page