Saturday, September 20, 2008

Learnings of the Week

Conditional Statements
Are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.


Types of Conditional Statements:
The If Statement
The If-Else Statement
The Nested-If Statement
The If-Else-If Ladder
The Switch Statement
The Nested Switch Statement


The If Statement -
In an if statement, if the expression evaluates to TRUE (1), the statement or the block of statements that forms the target of the if statement will be executed. Otherwise, the program will ignore the statement or the block of statements.

The If-Else Statement - If an if-else statement, if the expression is TRUE (1), the statement or block of statement after the if statement will be executed; otherwise, the statement or block of statement in the else statement will be executed.
Note: Only the code associated with the if or the code that is associated with the else executes, never both.

The Nested-If Statement - One of the most confusing aspects of the if statement in any programming language is nested ifs. A nested if is an if statement that is the object of either an if or else. This is sometimes referred to as “an if within an if.” The reason that nested ifs are so confusing is that it can be difficult to know what else associates with what if.

The Else-If-Else Ladder -
In an if-else-if ladder statement, the expression are evaluated from the top downward. As soon as a true condition is found, the statement associated with it is executed and the rest of the ladder will not be executed. If none of the condition is true, the final else is executed.

The Switch Statement - In a switch statement, a variable is successively tested against a list or integer or character constants. If a match is found, a statement or block of statement is executed. The default part of the switch is executed if no matches are found.

The Nested Switch Statement -
It is just a switch within a switch statement.

[Emerald May L. Caligdong]

No comments: