Home About Rice Downloads Documents Others Cooker CookerGX
Documents  >  Tutorial  >  ifstatement
if statement

Purpose of this chapter.

We will learn about the if statement.

Conditional branch statement.

The if statement is a statement of order to branch the execution control by the conditions.

The if statement is the following format.


if ( conditional-expression )

文...

elseif ( conditional-expression )

文...

else

文...

endif


the conditional-expression must be an expression that returns an instance of a bool class.

The if statement moves the execution control to the top of the first section where the conditional-expression is evaluated as true. All conditional-expression are false, and if there is an else section, the execution control will move to the top of the else section.

If the execution control reaches to the next elseif keyword or else keyword, Execution control will move to the next statement of the endif keyword.

The if statement must end with endif. The elseif section and else section are optional. The elseif sections are able to exist any number in the if statement. The else section is able to exist only one in the if statement.

if keyword

The 'if' keyword indicates that this statement is a if statement.

The end of the if statement.

The end of the if statement is represented by a endif keyword.

if section

The if section is located to the first of the if statement. Its range is up to the next keyword (elseif, else, endif) of the same statement.

The if section is the following format.


if ( conditional-expression )

statements...


If the conditional-expression of the if section evaluates as true, the execution control will move to the next statement of the conditional-expression. And, runs the statements in the section.

If the execution control reaches the next keyword (elseif, else, endif) of the same statement, the execution control will move to the next statement of the endif keyword.

The if section must be only one at the beginning of the if statement.

if keyword

The 'if' keyword indicates that this section is a if section.

It represents a if statement and if section at the same time.

Conditional expression.

the conditional-expression must be an expression that returns an instance of a bool class. Also, it must be enclosed by parentheses.

If the conditional-expression evaluates as true, the execution control will move to the next statement of the conditional-expression. And, runs the statements in the section.

Scope

The if section will generate a scope. Variable that has been declared in the section can be referred only within the section.

elseif section

The elseif sections are located to the next of the if section. Its range is up to the next keyword (elseif, else, endif) of the same statement.

The elseif section is the following format.


elseif ( conditional-expression )

statements...


If the conditional-expression of the elseif section evaluates as true, the execution control will move to the next statement of the conditional-expression. And, runs the statements in the section.

If the execution control reaches the next keyword (elseif, else, endif) of the same statement, the execution control will move to the next statement of the endif keyword.

The elseif section is optional. There can be any number in the if statement.

conditional expression.

the conditional-expression must be an expression that returns an instance of a bool class. Also, it must be enclosed by parentheses.

If the conditional-expression evaluates as true, the execution control will move to the next statement of the conditional-expression. And, runs the statements in the section.

Scope

The elseif section will generate a scope. Variable that has been declared in the section can be referred only within the section.

else section

The else section is located to the end of the if statement. Its range is up to the next endif keyword of the same statement.

The else section is the following format.


else

statements...


If the execution control reaches the else section, statements in the section will be executed unconditionally.

If the execution control reaches the endif keyword of the same statement, the execution control will move to the next statement of the endif keyword.

The else section is optional. And, it cannot exist two or more.

Scope

The else section will generate a scope. Variable that has been declared in the section can be referred only within the section.

Next
Previous
Copyright © Rice All rights reserved.