SlideShare a Scribd company logo
1 of 40
   Statements & block
   If Else
   Else If
   Switch
   While Loop
   For loop
   Do while loop
   Break & continue
   Goto & labels
 Expression+; = staement;
 More than one staement is called
  compund staments.

                     Single stament




                    Compund staments
   When a group of statements or
    compund staments protected by open
    and close braces is called block.
             Open brace



                            Block of codes



              Close brace
   Braces surrounded the staments of
    function definition.
                Open brace




                              Function definition




                Close brace
   Braces surround multiple statements
    of loop constructs too.
                 Open brace




                               Loop multiple
                               statements



                 Close brace
   Write a program to take two float
    numbers and do these tasks upon
    them
    ◦   Multiplication
    ◦   Division
    ◦   Subtraction
    ◦   Addition
    ◦   & find remainder
 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.
 Here is an example of if-else
 IF test is not true so the else part will
  execute.
   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.
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;
Switch (expression){
Case constant-expression:
statement;
Break;
Case constant-expression:
statement;
Break;
Case constant-expression:
statement;
Break;
Case constant-expression:
statement;
Break;
Default: statement;
}
 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.
   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
   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--
 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.
 In while loop we have only test-
  expression is tested.
 If expression testing results true then
  the statement or statements executes.
 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
 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?
 Write a program to display 1 to 100
  using
 For loop
 While loop
 Do-while loop
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
 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
Timesjobs.com
           Click me to hire




Check the links for more informations.
You can put feedback and comments.

More Related Content

What's hot

Control statements anil
Control statements anilControl statements anil
Control statements anilAnil Dutt
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statementFarshidKhan
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statementRaj Parekh
 
C language control statements
C language  control statementsC language  control statements
C language control statementssuman Aggarwal
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
Decision control structures
Decision control structuresDecision control structures
Decision control structuresRahul Bathri
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
C programming decision making
C programming decision makingC programming decision making
C programming decision makingSENA
 

What's hot (20)

Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
C language control statements
C language  control statementsC language  control statements
C language control statements
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
Decision control structures
Decision control structuresDecision control structures
Decision control structures
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
Control statements
Control statementsControl statements
Control statements
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Control Structures
Control StructuresControl Structures
Control Structures
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 

Viewers also liked

Viewers also liked (20)

Sony chassis az1-l_training_manual
Sony chassis az1-l_training_manualSony chassis az1-l_training_manual
Sony chassis az1-l_training_manual
 
Loop control in c++
Loop control in c++Loop control in c++
Loop control in c++
 
Dev C++ Code Basic Loop
Dev C++ Code Basic LoopDev C++ Code Basic Loop
Dev C++ Code Basic Loop
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Object Oriented Program
Object Oriented ProgramObject Oriented Program
Object Oriented Program
 
C++ 11 range-based for loop
C++ 11   range-based for loopC++ 11   range-based for loop
C++ 11 range-based for loop
 
C++ arrays part2
C++ arrays part2C++ arrays part2
C++ arrays part2
 
C++loop statements
C++loop statementsC++loop statements
C++loop statements
 
Flow control in computer
Flow control in computerFlow control in computer
Flow control in computer
 
While loop
While loopWhile loop
While loop
 
C++11
C++11C++11
C++11
 
[C++]3 loop statement
[C++]3 loop statement[C++]3 loop statement
[C++]3 loop statement
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
 
Flow chart programming
Flow chart programmingFlow chart programming
Flow chart programming
 
Loops
LoopsLoops
Loops
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++Revision notes for exam 2011 computer science with C++
Revision notes for exam 2011 computer science with C++
 
C++ classes
C++ classesC++ classes
C++ classes
 

Similar to Flow control in c++

Similar to Flow control in c++ (20)

While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
M C6java6
M C6java6M C6java6
M C6java6
 
Loops and iteration.docx
Loops and iteration.docxLoops and iteration.docx
Loops and iteration.docx
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
 
Control statements
Control statementsControl statements
Control statements
 
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdfUNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
 
07 flow control
07   flow control07   flow control
07 flow control
 
Control structures IN SWIFT
Control structures IN SWIFTControl structures IN SWIFT
Control structures IN SWIFT
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
C language 2
C language 2C language 2
C language 2
 
Chap3java5th
Chap3java5thChap3java5th
Chap3java5th
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
dizital pods session 5-loops.pptx
dizital pods session 5-loops.pptxdizital pods session 5-loops.pptx
dizital pods session 5-loops.pptx
 
Loop
LoopLoop
Loop
 
6.pptx
6.pptx6.pptx
6.pptx
 

More from Subhasis Nayak

More from Subhasis Nayak (19)

Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
 
Php, mysq lpart3
Php, mysq lpart3Php, mysq lpart3
Php, mysq lpart3
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
 
Jsp 01
Jsp 01Jsp 01
Jsp 01
 
Jsp 02(jsp directives)2003
Jsp 02(jsp directives)2003Jsp 02(jsp directives)2003
Jsp 02(jsp directives)2003
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Php, mysqlpart2
Php, mysqlpart2Php, mysqlpart2
Php, mysqlpart2
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Servlet & jsp
Servlet  &  jspServlet  &  jsp
Servlet & jsp
 
J2ee connector architecture
J2ee connector architectureJ2ee connector architecture
J2ee connector architecture
 
how to create object
how to create objecthow to create object
how to create object
 
Pointer in c++ part3
Pointer in c++ part3Pointer in c++ part3
Pointer in c++ part3
 
Pointer in c++ part2
Pointer in c++ part2Pointer in c++ part2
Pointer in c++ part2
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
C++ arrays part1
C++ arrays part1C++ arrays part1
C++ arrays part1
 
Introduction to network
Introduction to networkIntroduction to network
Introduction to network
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Text mode Linux Installation Part 01
Text mode Linux Installation Part 01Text mode Linux Installation Part 01
Text mode Linux Installation Part 01
 

Flow control in c++

  • 1.
  • 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;
  • 17.
  • 18. Switch (expression){ Case constant-expression: statement; Break; Case constant-expression: statement; Break; Case constant-expression: statement; Break; Case constant-expression: statement; Break; Default: 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.