Saturday, September 20, 2008

programming - NAVARRA

In this week, we learn a lot f things. we learned that the term used to display your statement is “printf” and the term used to scan the data you will enter is the “scanf”. And there is also a term to end the program which is the the “getch”.

We also discuss about the different types of conditional statement such as:
l The If statement
l The If-Else Statement
l The Nested-If Statement
l The If-Else-If Ladder
l The Switch Statement
l The Nested Switch Statement

The If statement:
· The general form of the If statement is:
if ( expression)
statement;
· Expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value.
· The general form of the If statement with block statement is:
if ( expression)
{
statement_sequence;
}
The If-Else statement:
· The general form of the if-else statement is:

If (expression)
statement_1;
else
statement_2;

· Where:
– If and else are reserved words
– Expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value.
– Statement_1 and statement_2 may either be a single C statement or a block of c statements
l 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.

Nested-If statement
l 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.
l This is sometimes referred to as “an if within an if.”
l The reason that nested ifs are so confusing is that it can be difficult to know what else associates with what if.

The if-else-if Ladder
l A common programming construct in C is the if-else- if ladder.
l The general form of the if-else-if ladder statement is:
if ( expression_1)
statement_1;
else if (expression_2)
statement_2;
else if (expression_3;
statement_3;
:
:
else
statement_else;

The switch statement
l The switch statement is a multiple-branch decision statement.
l The general form of the switch statement is:
switch (variable)
{
case constant1:
statement sequence_1;
break;
case constant2:
statement_sequence_2;
break;
:
:
default:
statement_sequence_default;
}
l In a switch statement, a variable is successively tested against a list or integer or character constants.
The Nested Switch Statement
l The general form of the nested switch statement is:
switch (variable)
{
case constant:{
switch (variable)
{
case constant1:
statement sequence_1;
break;
case constant2:
statement_sequence_2;
break;
}
break;
}
case constant2:
statement sequence;
break;
default:
statement sequence;
}

No comments: