Velocity Reviews > If statements

# If statements

Sheldon
Guest
Posts: n/a

 01-12-2007
Hi,

I would like to know if there is a limit to how many conditions can be
used in an if statement. For example:
if ( a && b && c && d && e && f.....) {
command
}

I am not suggesting ridiculous amounts like 20 but rather 4 or 5
conditions?

Is there a limit?

/Sheldon

Richard Heathfield
Guest
Posts: n/a

 01-12-2007
Sheldon said:

> Hi,
>
> I would like to know if there is a limit to how many conditions can be
> used in an if statement. For example:
> if ( a && b && c && d && e && f.....) {
> command
> }
>
> I am not suggesting ridiculous amounts like 20 but rather 4 or 5
> conditions?
>
> Is there a limit?

As far as I can tell, the only applicable limit is the length of a logical
source line! That's 509 in C90, and 4095 in C99.

In other words, you won't hit any practical limits unless you're trying
pretty hard.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.

santosh
Guest
Posts: n/a

 01-12-2007
Richard Heathfield wrote:
> Sheldon said:
> > Hi,
> >
> > I would like to know if there is a limit to how many conditions can be
> > used in an if statement. For example:
> > if ( a && b && c && d && e && f.....) {
> > command
> > }

<snip>
> As far as I can tell, the only applicable limit is the length of a logical
> source line! That's 509 in C90, and 4095 in C99.

Which can be extended with the line continuation character, which is a
backslash.

Sheldon
Guest
Posts: n/a

 01-12-2007

santosh skrev:

> Richard Heathfield wrote:
> > Sheldon said:
> > > Hi,
> > >
> > > I would like to know if there is a limit to how many conditions can be
> > > used in an if statement. For example:
> > > if ( a && b && c && d && e && f.....) {
> > > command
> > > }

> <snip>
> > As far as I can tell, the only applicable limit is the length of a logical
> > source line! That's 509 in C90, and 4095 in C99.

>
> Which can be extended with the line continuation character, which is a
> backslash.

Thanks!!

/S

=?utf-8?B?SGFyYWxkIHZhbiBExLNr?=
Guest
Posts: n/a

 01-12-2007
santosh wrote:
> Richard Heathfield wrote:
> > Sheldon said:
> > > Hi,
> > >
> > > I would like to know if there is a limit to how many conditions can be
> > > used in an if statement. For example:
> > > if ( a && b && c && d && e && f.....) {
> > > command
> > > }

> <snip>
> > As far as I can tell, the only applicable limit is the length of a logical
> > source line! That's 509 in C90, and 4095 in C99.

>
> Which can be extended with the line continuation character, which is a
> backslash.

You don't even need that. There is no requirement that all conditions
in an if statement appear on a single line. You can write

if (a
&& b
&& c
&& d)
{
/* ... */
}

Eric Sosman
Guest
Posts: n/a

 01-12-2007
santosh wrote:
> Richard Heathfield wrote:
>> Sheldon said:
>>> Hi,
>>>
>>> I would like to know if there is a limit to how many conditions can be
>>> used in an if statement. For example:
>>> if ( a && b && c && d && e && f.....) {
>>> command
>>> }

> <snip>
>> As far as I can tell, the only applicable limit is the length of a logical
>> source line! That's 509 in C90, and 4095 in C99.

>
> Which can be extended with the line continuation character, which is a
> backslash.

Nit-pick: Backslash-newline joins multiple *physical* source
lines into a single *logical* source line, whose length may be
subject to the limits Richard mentions. See section 5.1.1.2,
paragraph 1, point 2.

--

santosh
Guest
Posts: n/a

 01-12-2007
Eric Sosman wrote:
> santosh wrote:
> > Richard Heathfield wrote:
> >> Sheldon said:
> >>> Hi,
> >>>
> >>> I would like to know if there is a limit to how many conditions can be
> >>> used in an if statement. For example:
> >>> if ( a && b && c && d && e && f.....) {
> >>> command
> >>> }

> > <snip>
> >> As far as I can tell, the only applicable limit is the length of a logical
> >> source line! That's 509 in C90, and 4095 in C99.

> >
> > Which can be extended with the line continuation character, which is a
> > backslash.

>
> Nit-pick: Backslash-newline joins multiple *physical* source
> lines into a single *logical* source line, whose length may be
> subject to the limits Richard mentions. See section 5.1.1.2,
> paragraph 1, point 2.

That's a major correction; my post is incorrect.
Thanks.

 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 OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post John Crichton Ruby 6 07-12-2010 06:17 PM Vince Java 12 01-21-2008 01:18 PM Neil Zanella VHDL 8 10-20-2006 09:05 AM Harry George Python 6 02-23-2004 06:48 PM rajan VHDL 1 07-04-2003 07:22 AM