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.