Begin Programming Logo
Home | KPL | Object Pascal | General Programming | Code Database | About Us
   
Selection Statements
   
   

If Statements

This is a simple piece of code, whose structure is as follows:

If a statement is true or false (as specified by user) Then do something

A typical If statement can also include And's and Or's in the part of the code that comes before the then.
The if statement can also have an else part to it. The else will only be executed if the condition in the if statement is not true.

Example

If (X=5) Or (X=3) Then do something
Else do something different

Case Statements

Case statements are used when there are many possible choices which can be made.
For instance a letter of the alphabet can be one of 26 possible letters.
In such cases it is not practical to use many If statements. A case statement is used.

Example

Case X of
1 : Do something
2 : Do something else
3 : Do something completely different

Most case statements have this general structure. Some even have an else at the bottom for exceptions.

   

Valid XHTML 1.0 Transitional Valid CSS!