You are on page 1of 13

Control Statement/Decision making Statement

 If
 If else
 If else if ladder
 Nested if
 Switch

1. IF Statement
Syntax : if(condition)

Statement;

After if statement;

Flow Chart:
Program:

i. Code:

Output:

For True Value i.e., other than 0

For False Value i.e., 0


ii. Code :

Output:
For True Value

For False Value

iii. Code: 1
Output:
1.

2.

Code : 2

Output
1.
2.

Code: 3

Output: 1

Output: 2
2. IF else Statement
Syntax:

if(condition)

True block statement;}

Else

False block of statements;

After if else statement;

Flow Chart
Program:

Q- WAP to show that whether a person is eligible to vote or not on the basis of his/her age. If the person’s age is
greater than 18, then he/she is eligible, otherwise not.

Output 1.

Output 2

3. Nested IF Statement
Syntax:

If(condition1)

{
If (condition2)

If(condition3)

……..

Syntax 2

If(condition1)

If(condition2)

Inner if block statement;

Or else

Inner else block

Else

Outer else block statement;

After nested if else statements;


Flow Chart:

Without inner block statement:

With inner block state


Program:

Q- WAP that will receive age and salary from the user on the basis of following statements, show salary increment

(a) if age is 50 or more and salary is less than 60000, then Salary Increment by 10000

(b) If if age is 50 or more and salary is more than 60000, then salary increment by 5000

(c) otherwise iincrement by 3000

Output:1

Output: 2
4. If else if ladder statement
Syntax:

If(condition1)

Statement 1;

Else if(condition2)

Statement 2;

Else if(condition 3)

Statement 3;

……..

…….

………

Else if(condition n)

Statement n;

Else

Default statement;

Statement X(after if else if ladder)

Flow Chart:
Proogram:

Q- WAP that will show grades of students on the basis of marks.

a) If marks>80, then Grade A.


b) If marks>70, then Grade B.
c) If marks>60, then Grade C.
d) Otherwise grade D
Output: 1

Output: 2

Output: 3

Output : 4

You might also like