if ... else statements and syntax

suggest change

While if performs an action only when its condition evaluates to true, if / else lets you specify different actions when the condition is true and when the condition is false.

Example:

if (a > 1)
    puts("a is larger than 1");
else 
    puts("a is not larger than 1");

Just like the if statement, when the block within if or else consists of only one statement, the braces can be omitted (but doing so is not recommended, because it can easily introduce problems unintentionally). If there is more than one statement within the if or else block, the braces have to be used on that particular block.

if (a > 1) 
{
    puts("a is larger than 1");
    a--;
}
else 
{
    puts("a is not larger than 1");
    a++;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents