LOOPS BY: LAUREN & ROMEO.

Slides:



Advertisements
Similar presentations
WARM-UP: MON, APR 7 What are loops used for in programming? What are at least 2 different kinds of loops?
Advertisements

LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
COMP 14 Introduction to Programming Miguel A. Otaduy May 21, 2004.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Recognizing Patterns Counting: continually updating a value by a fixed amount Counting raindrops int dropCount = 0; //Raindrop counter while (dropCount.
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.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
© 2007 Lawrenceville Press Slide 1 Chapter 6 The while Statement  Loop structure that executes a set of statements as long as a condition is true  The.
© 2004 Pearson Addison-Wesley. All rights reserved February 20, 2006 ‘do’ and ‘for’ loops ComS 207: Programming I (in Java) Iowa State University, SPRING.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Repetition Statements while and do while loops
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
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 © 2012 Pearson Education, Inc. Chapter 5: Loops.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
While ( number
Catie Welsh February 9,  Friday - No Lab! ◦ Bring questions on Project 2  Lab 3 due on Friday 2.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Learning Javascript From Mr Saem
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Chapter 9 Repetition.
Chapter 4 Repetition Statements (loops)
REPETITION CONTROL STRUCTURE
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
Chapter 5: Control Structures II (Repetition)
Chapter 6 More Conditionals and Loops
Chapter 5: Control Structures II
Loop Structures.
CiS 260: App Dev I Chapter 4: Control Structures II.
Chapter 6 The while Statement
Chapter 5 Repetition.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Arrays, For loop While loop Do while loop
Looping and Repetition
Loops October 10, 2017.
Iteration with While You can say that again.
Debugging October 3, 2007 ComS 207: Programming I (in Java)
Outline Altering flow of control Boolean expressions
Chapter 9 Control Structures.
Loops A loop is a repetition control structure.
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
For Loops.
Control Statements Loops.
© 2016 Pearson Education, Ltd. All rights reserved.
Computer Science Core Concepts
Debugging October 4, 2006 ComS 207: Programming I (in Java)
JavaScript: Control Statements II
Loops.
Control Statements Loops.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
PROGRAM FLOWCHART Iteration Statements.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Building Java Programs
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
‘do’ and ‘for’ loops October 1, 2007 ComS 207: Programming I (in Java)
‘do’ and ‘for’ loops October 2, 2006 ComS 207: Programming I (in Java)
Looping and Repetition
Presentation transcript:

LOOPS BY: LAUREN & ROMEO

There are 3 types of loops: A loop allows you to execute a group of statements as many times as needed There are 3 types of loops: 1 2 3 Do-While While For

Do-while A loop that executes statements before checking the Boolean expression in the while statement. Always loops at least once EXAMPLE: Number is declared as 0 int number=0; do{ number+=1; }while(number<=10) 1 is added to the variable: number every time loop initiates CONDITION: loop initiates when the number is below or equal to 10.

while A while statement is a loop that checks the Boolean expression before executing the statements within the loop. Does not always loop once EXAMPLE: Number is declared as 0 int number=0; while(number<10) { number+=1; } 1 is added to the variable: number every time loop initiates CONDITION: loop initiates only when the number is below 10.

for A for statement is a counter loop that counts the number of times the statements in the loop are iterated EXAMPLE: Int i is declared as 0 Loop initiates when i is below or equal to 10 For (int i=0;i<=10;i++){ System.out.println(“Hello”); } 1 is added to i every time loop iterates Loop displays the phrase “hello” every time

Nested Loop EXAMPLE: A nested loop is a loop within a loop for loop will iterate 10 times int num = 0; for (int i=0;i<=10;i++){ do{ num+=1; System.out.println(“Hello”); }while(num==i); } 1 is added to the variable: num every time loop iterates CONDITION: do-while loop will stop iterating when num is equal to i

Infinite Loops EXAMPLE: int number = 0; do { number += 1; An infinite loop is a loop that contains an error to make it iterate infinite times because the condition is never met EXAMPLE: Number is declared as 0 int number = 0; do { number += 1; } while (number >0); 1 is added to the variable: number every time the loop iterates CONDITION: loop initiates when the number is greater than 0.