if loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fsl123
    New Member
    • Sep 2007
    • 1

    if loop

    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
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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

    Comment

    Working...