Connecting Tech Pros Worldwide Forums | Help | Site Map

if loop

Newbie
 
Join Date: Sep 2007
Posts: 1
#1: Sep 26 '07
HI All,

the syntax of "if loop in C" is

if (Condition)
{
statements;
}

but this if loop terminated by a NULL statement( ; ) also works..
if (Condition)
{
statements;
};

CAn anybody explains me the exact reason for how this works?

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Sep 26 '07

re: if loop


Quote:

Originally Posted by fsl123

HI All,

the syntax of "if loop in C" is

if (Condition)
{
statements;
}

but this if loop terminated by a NULL statement( ; ) also works..
if (Condition)
{
statements;
};

CAn anybody explains me the exact reason for how this works?

First, the if statement is not a loop, it's a conditional statement. Loops are "do",
"while" and "for" statemens.

C also has an empty statement, terminated by a semicolon. And that's what
you have: an if statement followed by an empty statement.

kind regards,

Jos
Reply


Similar C / C++ bytes