computational expression
play

Computational Expression Loops Janyl Jumadinova 16 October, 2019 - PowerPoint PPT Presentation

Computational Expression Loops Janyl Jumadinova 16 October, 2019 Janyl Jumadinova Computational Expression 16 October, 2019 1 / 7 Control Structures Three Groups of Control Structures 1 Sequential Structure - It is just built into the


  1. Computational Expression Loops Janyl Jumadinova 16 October, 2019 Janyl Jumadinova Computational Expression 16 October, 2019 1 / 7

  2. Control Structures Three Groups of Control Structures 1 Sequential Structure - It is just built into the language itself. Janyl Jumadinova Computational Expression 16 October, 2019 2 / 7

  3. Repetition Statements Loops A portion of a program that repeats a statement or a group of statements is called a loop. The statement or group of statements to be repeated is called the body of the loop. There must be a means of exiting the loop. Janyl Jumadinova Computational Expression 16 October, 2019 3 / 7

  4. Loop Bugs Common loop bugs: Unintended infinite loops Off-by-one errors Testing equality of floating-point numbers The loop may terminate for some input values, but not for others. Janyl Jumadinova Computational Expression 16 October, 2019 4 / 7

  5. Break Statement A break statement can be used to end a loop immediately. The break statement ends only the innermost loop or if statement that contains the break statement. Janyl Jumadinova Computational Expression 16 October, 2019 5 / 7

  6. Break Statement A break statement can be used to end a loop immediately. The break statement ends only the innermost loop or if statement that contains the break statement. break statements make loops more difficult to understand. Use break statements sparingly (if ever). Janyl Jumadinova Computational Expression 16 October, 2019 5 / 7

  7. Janyl Jumadinova Computational Expression 16 October, 2019 6 / 7

  8. Continue in Loops A continue statement : Ends current loop iteration Begins the next one Do not use unless necessary – Introduce unneeded complications Janyl Jumadinova Computational Expression 16 October, 2019 7 / 7

Recommend


More recommend