emanfman 17 Newbie Poster

Hi emanfman,

I agree with MOST of your post, but the syntax you give for the "if" statement is, while it will probably compile, misleading at best.

There is no multiple conditions separated by commas in an "if" statement. The syntax of the multiple types of "if" statement is as follows:

if ( condition ) statement1;

if ( condition ) statement1; else statement2;

if ( condition )
{
   statement1;
   statement2;
}

if ( condition )
{
   statement1;
   statement2;
}
else
{
   statement3;
   statement4;
}

Only the "for" statement has three parts to it, and they are separated by semicolons and not commas.

Tom

From the near JavaScript example he gave, with the conditions separated by &&, I use a comma because it makes the "if" statement true only if ALL the conditions are true. Technically, it is still correct to use the && though.

emanfman 17 Newbie Poster

I saw a major syntax error. Maybe you were thinking Java?

The proper syntax for an if statement is:

if (condition1, condition2, condition3...) {statement1; statement2;}

If it's simpler, here it is on several lines:

if (condition1, condition2, condition3...)
{
statement1;
statement2;
}

If you wanted something to be done if it were evaluated false, just add an else at the end, followed by braced code:

if (condition1, condition2, condition3...)
{
statement1;
statement2;
}
else
{
statement3;
statement4;
}

Notice that the if...else statement doesn't require a semicolon (;) after the braces... it acts like a function.

Try fixing up your code with the right syntax.

Remember - you need the conditions in parentheses (()) and the function in braces({}).

Also, something I just realized is that you have no function for the "if" and the else has no condition.

Hope that helps!