Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: if 'also' else statment

Thread Tools

Re: if 'also' else statment

Posts: n/a
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)
if (Day == Sunday)

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

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.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: if 'also' else statment William McNicol C Programming 2 01-09-2010 12:30 PM
Re: if 'also' else statment TonyMc C Programming 1 01-08-2010 04:23 PM
PIX route inside statment John Cisco 1 09-27-2005 03:06 AM
Using "For Each ctrl In.." Statment Inside UserControl crjunk ASP .Net 2 09-03-2004 06:23 PM
Return statment JL ASP .Net 2 12-17-2003 10:47 AM