Difference between revisions of "The If Statement"

From Catglobe Wiki
Jump to: navigation, search
 
Line 1: Line 1:
 
[[Category:Program_Control_Statements]]
 
[[Category:Program_Control_Statements]]

+
{{HelpFiles}}
  
 
===The If Statement===
 
===The If Statement===

Latest revision as of 08:15, 14 December 2011



The If Statement

The complete syntax of the if statement is:

if (condition) statement;

else statement;

where the targets of the if and else are single statements. The else clause is optional. The targets of both the if and else can be blocks of statements. The general form of the if using blocks of statements is:

if (condition)

{

Statement sequence

}

else

{

Statement sequence

}

Here is a simple example that uses simple if and else statements:

{

if (SomeValue == 0) print("value == 0");

else print("value != 0");

}

An else statement always refers to the nearest if statement that is within the same block as that else and not already associated with another else.