in this presentation i will explain you about Statements & block, If Else, ElseI f, Switch, While Loop, For loop, Do while loop, Break & continue in c++
2. Statements & block
If Else
Else If
Switch
While Loop
For loop
Do while loop
Break & continue
Goto & labels
3. Expression+; = staement;
More than one staement is called
compund staments.
Single stament
Compund staments
4. When a group of statements or
compund staments protected by open
and close braces is called block.
Open brace
Block of codes
Close brace
5. Braces surrounded the staments of
function definition.
Open brace
Function definition
Close brace
6. Braces surround multiple statements
of loop constructs too.
Open brace
Loop multiple
statements
Close brace
7.
8.
9.
10.
11. Write a program to take two float
numbers and do these tasks upon
them
◦ Multiplication
◦ Division
◦ Subtraction
◦ Addition
◦ & find remainder
12. If – else is used to control the flow with
the condition.
In If-Else, if the IF test is true then if
statements will executes.
if IF test is false then Else staements will
execute.
Be – careful to put open & close braces if
you have more than one staement in IF
or ELSE part.
13. Here is an example of if-else
IF test is not true so the else part will
execute.
14.
15. Here we can check as much test as we
want.
Each else work will like separate IF.
All have one else.
If all test fails then only else part will
excute.
As i told we can do any number of tests.
But it takes hell amount of time. To avoid
this we will use switch – case.
16. If (tes-expression)
True –statement;
Else If (tes-expression)
True –statement;
Else If (tes-expression)
True –statement;
Else If (tes-expression)
True –statement;
Else If (tes-expression)
True –statement;
Else
False statement;
19. In switch-case ,we are switching on a
expression . The expression must be
integer value. We can do switch
caseupon string, float or anything else.
There are more than one case.
Here we are comparing the case value
with switch.
We have a default value if none of case
satisfies.
20.
21.
22. Executing a block of code for a certain no of
periods.
We need a condition to test.
We have to increment or decrement.
If we have more than one statement then we
need to put those within curly brace’{}’
We have three types of loops
◦ For loop
◦ While loop
◦ Do – while loop
23. For a loop we need
Initialized from where you want to start
◦ I = 0 or [or any number from where you want]
Test expression or you can say test
condition
◦ I <= or< or >= or > [certain value]
Adjustments(increment or decrement)
◦ i++
◦ i--
24.
25.
26. When we don’t use any initializer, test-
expression & adjustment. The loop
becomes infinite loop.
Can we use infinite loop? Yes but with a
break and a condition.
The loop will continue infinite until unless
our condition satisfies. Once condition
satisfies we will come out using break;
statement.
27.
28. In while loop we have only test-
expression is tested.
If expression testing results true then
the statement or statements executes.
29.
30.
31. In do while loop first the statements
executes
Next is testing expression
Here the must run once even the
expression test id false.
But in for & while to execute statement
the expression must be true
32.
33.
34.
35. Write all the three programs which I
showed you on previous slide
initializing the I value to ‘7’.
Answer us what you will get and
when?
36. Write a program to display 1 to 100
using
For loop
While loop
Do-while loop
37. 1. Write a program to display all odd numbers in
between 1 to 50.advise
1. Use for/while loop
2. Write a program to display all even numbers in
between 1 to 50.advise
1. Use for/while loop
3. Write a program to display all numbers in between 1
to 50 which are less than 26.advise
1. Use for/while loop
4. Write a program to display all numbers in between 1
to 50 which are greater than 25.advise
1. Use for/while loop
38. When break occurs it send the
execution to out of the loop or switch.
When continue occurs it sends the
execution right to the testing
expression.
These two can be used inside of
switches and loops
39.
40. Timesjobs.com
Click me to hire
Check the links for more informations.
You can put feedback and comments.