Introduction To Programming
Introduction To Programming
If (condition)
statement ;
If Statement in C
If ( condition )
{
statement1 ;
statement2 ;
:
}
If statement in C
if (age1 > age2)
cout<<“Student 1 is older
than student 2” ;
Relational Operators
< less than
<= less than or equal to
== equal to
>= greater than or equal to
> greater than
!= not equal to
Relational Operators
a != b;
X = 0;
X == 0;
Example
#include <iostream.h>
main ( )
{
int AmirAge, AmaraAge;
AmirAge = 0;
AmaraAge = 0;
Process
Flow line
Continuation mark
Decision
Flow Chart for if statement
Entry point for IF block
IF
Condition
Then
Process
AND &&
OR ||
Logical Operators
If a is greater than b
AND c is greater than d
In C
if(a > b && c> d)
if(age > 18 || height > 5)
if-else
if (condition)
{
statement ;
-
-
}
else
{
statement ;
-
-
}
if-else
Entry point for IF-Else block
IF
Condition
Then
Process 1
Else
Process 2
!true = false
!false = true
If (!(AmirAge > AmaraAge))
?
Example
?
If (age > 18)
Nested if
{
If(height > 5)
{
:
}
}
Make a flowchart of this nested if structure…
In Today’s Lecture
Decision
– If
– Else
Flowcharts
Nested if