LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.

Slides:



Advertisements
Similar presentations
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Introduction to Computers and Programming Lecture 9: For Loops New York University.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
Chapter 6: Iteration Part 1. To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To understand.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
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 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
While ( number
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
CHAPTER 4 REPETITION STRUCTURES 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Identify the Appropriate Method for Handling Repetition
FOP: While Loops.
Chapter 6: Loops.
Chapter 4 Repetition Statements (loops)
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Chapter 5: Repetition Structures
Topic 5 for Loops -Arthur Schopenhauer
( Iteration / Repetition / Looping )
Web Programming– UFCFB Lecture 16
ITM 352 Flow-Control: Loops
Chapter 4 Repetition Structures
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Chapter 4 Repetition Structures
Arrays, For loop While loop Do while loop
Looping and Repetition
MSIS 655 Advanced Business Applications Programming
Creativity in Algorithms
Outline Altering flow of control Boolean expressions
Introduction to Object-Oriented Programming with Java--Wu
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Loops CIS 40 – Introduction to Programming in Python
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
LOOPS BY: LAUREN & ROMEO.
CMPT 102 Introduction to Scientific Computer Programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 6: Repetition Statements
Computing Fundamentals
Introduction to Repetition Structures
ICT Programming Lesson 3:
Flowcharts and Pseudo Code
Class 4: Repetition Pretest Posttest Counting Flowchart these!
Seating “chart” Front - Screen rows Back DOOR.
Chapter 4: Repetition Structures: Looping
Repetition Statements (Loops) - 2
Based on slides created by Bjarne Stroustrup & Tony Gaddis
PROGRAM FLOWCHART Iteration Statements.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
The structure of programming
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.
CS2011 Introduction to Programming I Loop Statements (I)
Chapter 13 Conditional Repetition
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Review of Previous Lesson
How to allow the program to know when to stop a loop.
while Loops Looping Control Statement
Looping and Repetition
Presentation transcript:

LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17

In this lesson, you will: Explain that a while loop continues to run while a boolean condition remains true. Translate a real-life activity with repeated components into a form that could be represented by a while loop. Analyze a while loop to determine if the initial condition will be met, how many times the loop will run, and if the loop will ever terminate. Write programs that use while loops in a variety of contexts.

Vocabulary: Iterate - To repeat in order to achieve, or get closer to, a desired goal. while loop - a programming construct used to repeat a set of commands (loop) as long as (while) a boolean condition is true. Counters: Variables that count how many times a while loop has run, also called iterators, can be used to control the number of times a while loop runs. Infinite Loops: The final example in this activity guide produces an “infinite loop.” This means that the computer (or person implementing the algorithm) will cycle through a set of commands forever, because the while loop condition is always true. Infinite loops are almost always undesirable, but they can be deceptively easy to create by mistake.

while loops repeat a set of steps until a certain condition is met while loops repeat a set of steps until a certain condition is met. Like conditional statements, while loops use Boolean expressions to determine if they will run and how many times.

 The structure of a while loop by demonstrating how a conditional statement that “loops” back on itself can be used to repeatedly execute a block of commands.

This conditional statement loops back on itself This conditional statement loops back on itself. As a result, the conditional might be evaluated multiple times. As a result, the same command is running multiple times.

The structure we just explored is called a “while loop The structure we just explored is called a “while loop.” When you look at the flowchart, you can see that we “loop through” a command as long as, or “while,” a condition is true.  while loops are a way we can easily represent a process that includes many repeated steps.

Distribute: Flowcharts with While Loops - Activity Guide to each student.

Errors in writing a while loop include: Writing the condition on which the while loop should stop rather than continue. Not including steps in the while loop that will make the condition false at some point (i.e., creating an infinite loop)

Go into Code Studio. Do the levels Go into Code Studio. Do the levels. Show me #21 – roll the dice with counter (finished project) Turn in Activity Guide: flow charts with while loops

Things to pay attention to when creating while loops. It repeats a set of commands. It continues to run “while” a Boolean expression is true. It is called a loop because it “loops through” a set of commands. Visually it looks like a loop when shown in a flowchart. Things to pay attention to when programming while loops: Something inside the while loop has to update the variable in the condition so the while loop will stop while loops may never run if the condition begins as false while loops can become infinite if the condition never becomes false Off-by-one errors are common with while loops