Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.

Slides:



Advertisements
Similar presentations
June 10, 2015ICS102: while & do-while1 while and do-while Statements.
Advertisements

1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Chapter 5: Control Structures II (Repetition)
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Flow of Control Loops – Chapter 3.2. Java Loop Statements: Outline the while Statement the do-while Statement the for Statement.
Chapter 5: Repetition Statements. In this chapter, you will learn about: Basic loop structures while loops Interactive while loops for loops Loop programming.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Principles of Programming - NI July Chapter 5: Structured Programming In this chapter you will learn about: Sequential structure Selection structure.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
CPS120 Introduction to Computer Science Iteration (Looping)
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
LOOPS In the Name of Allah The Most Merciful The Most Compassionate LOOPS
Do-while and for Loops Opening Discussion zWhat did we talk about last class? zAt the end of last class I asked you to write a loop that would.
Chapter 8 Repetition Statements. Introduction Iteration - process of looping or the repetition of one or more statements Loop body - the statement, or.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Chapter 5: Structured Programming
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
Fundamental Programming Fundamental Programming for Loops.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CPS120 Introduction to Computer Science Iteration (Looping)
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
1 Chapter 3: Loops and Logic. 2 Control Statements If statement Example NumberCheck.java Relational operators (, >=, ==, !=) Using code blocks with If.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
1 1 Additional Control Structures Chapter 9 2 New and Improved... Ways to branch Ways to write loops Understanding the break and continue statements.
Chapter 6 - Repetition. while Loop u Simplest loop u Two parts: test expression and loop body u Pre-tested loop –Execute loop body if test true –Bypass.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
While ( number
Repetition Statements b Repetition statements allow us to execute a statement multiple times repetitively b They are often simply referred to as loops.
LOOPS CHAPTER Topics  Four Types of Loops –while –do…while –for –foreach  Jump Statements in Loops –break –continue 2.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
LOOPS IN ‘C’ PROGRAMMING. V ERY O FTEN, Y OU W ILL W ANT TO D O S OMETHING M ORE T HAN O NCE HA.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
Chapter 9 Repetition.
CS161 Introduction to Computer Science
Chapter 5 Repetition.
Arrays, For loop While loop Do while loop
Loop Control Structure.
MSIS 655 Advanced Business Applications Programming
Outline Altering flow of control Boolean expressions
Chapter 9 Control Structures.
Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9)
for, do-while and switch statments
LOOPS BY: LAUREN & ROMEO.
Chapter 6: Repetition Statements
JavaScript: Control Statements II
CHAPTER 21 LOOPS 1.
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
CSCI 1100/1202 February 6, 2002.
Presentation transcript:

Chapter 7 LOOPING OPERATIONS: ITERATION

Chapter 7 The Flow of the while Loop

Chapter 7 while Loop Syntax while (test expression) { statement 1; statement 2; statement n; } //END WHILE

Chapter 7 DebuggingTip Remember, an infinite loop is the result of a logical error in your program. The compiler will not detect an infinite loop condition. For this reason, you should always desk- check your loop structures very closely prior to coding and execution. A little time desk-checking will save you a lot of time at the keyboard.

Chapter 7 The Flow of the do/while Loop

Chapter 7 do/while Loop Syntax do { statement 1; statement n; } //END DO/WHILE while (test expression);

Chapter 7 The Flow of the for Loop

Chapter 7 for Loop Syntax for (int counter = initial value; counter test; increment or decrement counter) { statement 1; statement 2; statement n; } //END FOR

Chapter 7 Tips –Never change the for loop counter within the body of the loop. –Do not place a semicolon at the end of the first line of the for statement unless you purposely want to create a time delay.

Chapter 7 The continue Statement When a continue statement is executed within a loop, only the current iteration is terminated and loop execution “continues” to the next iteration.

Chapter 7 The break Statement When a break statement is executed within a loop, the loop “breaks” and all loop iterations are terminated. Execution then passes to the next sequential statement after the loop.

Chapter 7  Use while whenever there is a possibility that the loop statements will not need to be executed.  Use do/while when the loop statements must be executed at least once. Use for when it can be predetermined exactly how many times the loop statements must be executed.