Intruduction conditional statement

21
conditional Statement Presented by : Khwaja Agha Karimi Phone 0093784302263 Email [email protected]

Transcript of Intruduction conditional statement

Page 1: Intruduction conditional statement

conditional Statement

Presented by :

Khwaja Agha KarimiPhone 0093784302263Email [email protected]

Page 2: Intruduction conditional statement

Welcome to our presentation

Page 3: Intruduction conditional statement

The topic we’ll present >>>

What conditional statements ?What is Types conditional

statements?If statements with exampleIf else statement with exampleNested if with exampleSwitchLoop

Page 4: Intruduction conditional statement

What is conditional?The conditional statement are used to execute the or

(ignore) a set of statement after testing the a condition

The condition statement are also called selection statement

Page 5: Intruduction conditional statement

Usage of conditional statement in life ?I am learning c, c++ I am confuse how it work in

real lifeIn programming each function have a reason Lets say about conditional statementA user going to signing up for Facebook bout we

don't want the users signing up of age less than 15 years old. If user age is less than 15 it should terminate the sign up page and give a reason saying

“sorry your too Young”Here we use if else statement behind situation

Page 6: Intruduction conditional statement

If statement ?

If statement is used to execute or ignore a set of statement after testing the condition

Syntax if(condition)Statement -1;Statement -2;

Page 7: Intruduction conditional statement

Program of If Statement?

Page 8: Intruduction conditional statement

If else statement ??

THIS IS THE ANOTHER FORM OF THE IF STATEMENT IT IS USE FOR MAKING TWO WAY DECISION IN THIS STATEMENT ONE CONDITION AND TWO BLOCK OF STATEMENTS ARE GIVEN.

SYNTAXIF(CONDITION)STATEMENT -1;ELSE STATEMENT -2;

Page 9: Intruduction conditional statement

Program of If-else statement??

Page 10: Intruduction conditional statement

If –else statement example in real life??

If it id raining I shall not water the plants , else I have to water the plants.

now we can write it in pseudo code If (raining == true) Do not water Else Do water

Page 11: Intruduction conditional statement

Nested if statementNested if When an if statement is used within another if statement it is called nested statement.If the condition-1 is true then the control shift to the next if statement and the condition-2 is testedIf the condition-2 is true then the statement-2 is executeThe control will pass to statement -3 and this statement will executeIf the condition-2 is false thestatement-2 is skipped and the control shift to the statement-3 and it will execute.Syntax:If (condition-1){If (condition-2){ statement-2}Conditon-3

Page 12: Intruduction conditional statement

Example of nested if in real life

If a boy age is more the 18 if his nationality was Afghan than he can give the vote in election now we change it in pseudo code if (age>18) { if (nationality ==‘Afghan’) cout<<“you Can Give the Vote\n”; } else Cout<<“you can not give the vote”;

Page 13: Intruduction conditional statement

Program of nested if Void main() { In a,b,c; Cout<<“enter first value\n”; Cin>>a; Cout<<“enter the 2nd value\n”; Cin>>b; Cout<<“enter the 3rd value\n”Cin>>c;If(a==b){If(a==c)Cout<<“these values are equal\n”;} else cout<<“these value are differents”;

Page 14: Intruduction conditional statement

What is switch Statement ?Switch statement is use when a multiple choice

are given and one choice be selected.When the switch statement is executed the given

expression is first evaluate and then value returned by the expression is compared with the values of the constant given in each case if the value match with co-

nstant value of a case then the statement of that case are execute

Keyword default is also used in the body of the switch if no case matched then the statement default are execute

Break statement Break statement is used to exit from the body of

the switch

Page 15: Intruduction conditional statement

example of switch in Real life ?

Let a company allows you a family tour, but the budget is not confirmed yet so, you would pre-plan the tour ? For this based on number of family member ready for this tour ,you would collect information for the tour expense of different destination and later on, select which one suits to your budget

Page 16: Intruduction conditional statement

What is syntax of switch Statement ?Switch(expression){Case constant-1;Statements;Break;Case const-2;Statements;Break;Case const-3;Statements;DefaultStatements;}

Page 17: Intruduction conditional statement

Program of switch statement?

Page 18: Intruduction conditional statement

What is Loop?

Loop is the repetition of the statement

The statement in a loop are execute for a specified number of time until some given condition

return true.

Page 19: Intruduction conditional statement

Example of Loop in real life?How about the act of walking :You know how to move your left

leg.You know how to move you right

legNow do that repeatedly (via a

loop)Until you arrive at your

destination.

Page 20: Intruduction conditional statement

THANKS FOR LISTENING

US

Page 21: Intruduction conditional statement

Any Question ??