Flow control in c++

2,795 views
2,643 views

Published on

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 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total views
2,795
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
0
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Flow control in c++

  1. 1.  Statements & block  If Else  Else If  Switch  While Loop  For loop  Do while loop  Break & continue  Goto & labels
  2. 2.  Expression+; = staement;  More than one staement is called compund staments. Single stament Compund staments
  3. 3.  When a group of statements or compund staments protected by open and close braces is called block. Open brace Block of codes Close brace
  4. 4.  Braces surrounded the staments of function definition. Open brace Function definition Close brace
  5. 5.  Braces surround multiple statements of loop constructs too. Open brace Loop multiple statements Close brace
  6. 6.  Write a program to take two float numbers and do these tasks upon them ◦ Multiplication ◦ Division ◦ Subtraction ◦ Addition ◦ & find remainder
  7. 7.  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.
  8. 8.  Here is an example of if-else  IF test is not true so the else part will execute.
  9. 9.  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.
  10. 10. 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;
  11. 11. Switch (expression){ Case constant-expression: statement; Break; Case constant-expression: statement; Break; Case constant-expression: statement; Break; Case constant-expression: statement; Break; Default: statement; }
  12. 12.  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.
  13. 13.  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
  14. 14.  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--
  15. 15.  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.
  16. 16.  In while loop we have only test- expression is tested.  If expression testing results true then the statement or statements executes.
  17. 17.  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
  18. 18.  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?
  19. 19.  Write a program to display 1 to 100 using  For loop  While loop  Do-while loop
  20. 20. 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
  21. 21.  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
  22. 22. Timesjobs.com Click me to hire Check the links for more informations. You can put feedback and comments.

×