Intruduction conditional statement
-
Upload
khwaja-agha-karimi -
Category
Software
-
view
19 -
download
0
Transcript of Intruduction conditional statement
Welcome to our presentation
The topic we’ll present >>>
What conditional statements ?What is Types conditional
statements?If statements with exampleIf else statement with exampleNested if with exampleSwitchLoop
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
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
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;
Program of If 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;
Program of If-else 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
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
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”;
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”;
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
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
What is syntax of switch Statement ?Switch(expression){Case constant-1;Statements;Break;Case const-2;Statements;Break;Case const-3;Statements;DefaultStatements;}
Program of switch 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.
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.
THANKS FOR LISTENING
US
Any Question ??