An if statement tests
conditions, executing a block of statements when a
condition is true.
The general format of
an if conditional statement is as follows:
if (
condition )
{
block
of statements
}
elseif ( condition )
{
block
of statements
}
else
{
block
of statements
}
The if statement
consists of three parts:
if: This part is required. Only one if is allowed.
It tests a condition:
• If the condition is true: The block of statements is executed. After
the statements are executed, the script moves to the next instruction following
the conditional statement; if the conditional statement contains any elseif or
else sections, the script skips over them.
• If the condition is not true: The block of statements is not executed. The
script skips to the next instruction, which can be an elseif, an else, or the
next instruction after the if conditional statement.
elseif: This part is optional. You can use more than
one elseif if you want. An elseif also tests a condition:
• If the condition is true: The block of statements is executed. After executing
the block of statements, the script goes to the next instruction following the conditional
statement; if the if statement contains any additional elseif sections or an
else section, the script skips over them.
• If the condition is not true: The block of statements is not executed. The
script skips to next instruction, which can be an elseif, an else, or the next
instruction after the if conditional statement.
else: This part is also optional. Only one else is
allowed. This part doesn’t test a condition, but rather it executes the block
of statements. The script enters the else section only when the if section and
all the elseif sections are not true.
Written by
“Shojib”
No comments:
Post a Comment