3. The topic we’ll present >>>
What conditional statements ?
What is Types conditional statements?
If statements with example
If else statement with example
Nested if with example
Switch
Loop
4. 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
5. Usage of conditional statement in life ?
I am learning c, c++ I am confuse how it work in real life
In programming each function have a reason
Lets say about conditional statement
A 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
6. 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;
10. 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
11. Nested if statement
Nested 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 tested
If the condition-2 is true then the statement-2 is execute
The control will pass to statement -3 and this statement will execute
If 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
12. 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 Voten”;
}
else
Cout<<“you can not give the vote”;
13. Program of nested if
Void main()
{
In a,b,c;
Cout<<“enter first valuen”;
Cin>>a;
Cout<<“enter the 2nd valuen”;
Cin>>b;
Cout<<“enter the 3rd valuen”
Cin>>c;
If(a==b)
{
If(a==c)
Cout<<“these values are equaln”;
}
else
cout<<“these value are differents”;
14. 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
15. 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
16. What is syntax of switch Statement ?
Switch(expression)
{
Case constant-1;
Statements;
Break;
Case const-2;
Statements;
Break;
Case const-3;
Statements;
Default
Statements;
}