If statements

S

Sheldon

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
 
R

Richard Heathfield

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.
 
S

santosh

Richard said:
Sheldon said:
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.
 
G

Guest

santosh said:
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)
{
/* ... */
}
 
E

Eric Sosman

santosh said:
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.

--
 
S

santosh

Eric said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top