answersLogoWhite

0

How If and else run at a time?

User Avatar

Anonymous

13y ago
Updated: 8/20/2019

The standard syntax is:

if( conditional_expression )

statement;

[[else if( conditional_expression )

statement;

[else if...]]

else statement;]

[] denotes optional components. Each statement may be a single statement, or may be multiple statements surrounded by braces {}.

The if( conditional expression ) statement; is the only required component. In plain English, this reads: if the conditional expression is true, then execute the following statement, otherwise skip to the line following the statement.

If the next line is an else statement, then the line reads: if the conditional expression is true, then execute the statement and skip over the else statement. But if the conditional expression is false, then skip over the statement and execute the else statement instead.

if( conditional_expression )

statement; // execute when conditional expression is true

else

statement; // execute when conditional expression is false

The statement following the else can be another ifstatement (a nested if):

if( conditional_expression_1 )

statement; // execute when conditional_expression_1 is true.

else if( conditional_expression_2)

statement; // execute when conditional_expression_1 is false and _2 is true.

else

statement; // execute when both _1 and _2 are both false.

Note that if an else statement is used without a following if statement, it must appear after all other else if statements.

User Avatar

Wiki User

13y ago

What else can I help you with?