Std-10-Computer-Chapter 13 Decision Structures
Std-10-Computer-Chapter 13 Decision Structures
Simple if statement
The simplest way of decision structure is the if statement.
If statement is used in the program for decision making and to change the flow of
program execution.
Syntax:
if(test expression)
{
Statement-block;
}
Some next instruction of the program;
The logical operators are used in test expression.
Note: test expression should not end with a semi-color (;)
If the test expression is true then executes the statement-block and if the test expression
is false then computers skips the statement-block and executes the next instruction of
the program.
C programming language assumes any non-zero and non-null values as true and if it
either zero or null then it is assumed as false value.
Presented by Nuzhat Ibrahim Memon 1
if….else statement
In simple if statement there is only one statement block, which gets executed only when
the test expression is true.
Simple if statement takes no action in case when the test expression is false.
Many times, there is a need to takes an action when the test expression is true as well as
when it is false, then in such cases, the if…else structure is useful.
if..else is a two way statement:
o If the condition is true in if ... else statement if part is executed.
o If the condition is false in if...else statement else part is executed
Syntax:
if(test expression)
{
true Statement-block;
}
else
{
false Statement-block;
}
if(test expression-1)
{
statement-block-1;
}
else if(test expression-2)
{
statement-block-2;
}
………………..
………………..
else if(test expression n){
statement-block-n;
}
else
{
default-statement-block;
}
program-statement-x;