FLUENCY WITH INFORMATION TECNOLOGY

Slides:



Advertisements
Similar presentations
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
Repeating Actions While and For Loops
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
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.
Copyright © Texas Education Agency, Computer Programming For Loops.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
Copyright 2009 by Pearson Education Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos: Ch.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved For Loops October 16, 2013 Slides by Evan Gallagher.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
CPS120 Introduction to Computer Science Iteration (Looping)
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
1 Ch. 6 Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit number of times.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 13 Conditional.
CPS120 Introduction to Computer Science Iteration (Looping)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Controlling Program Flow with Looping Structures
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 13 Conditional.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Testing Programs with Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
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.
Chapter 6 Controlling Program Flow with Looping Structures.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Karel J. Robot Chapter 6 Instructions That Repeat.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Structured Programming The Basics
FOP: While Loops.
Chapter 6: Loops.
REPETITION CONTROL STRUCTURE
Introduction To Repetition The for loop
Chapter 3 Loops Section 3.3 Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Karel J Robot Chapter 6.
Chapter 5: Repetition Structures
Topics Introduction to Repetition Structures
Web Programming– UFCFB Lecture 16
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Repetition Chapter 6 12/06/16 & 12/07/16 1 1
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Iteration with While You can say that again.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Introduction to pseudocode
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Chapter 6: Repetition Statements
Loop Strategies Repetition Playbook.
Introduction to Repetition Structures
ICT Programming Lesson 3:
CprE 185: Intro to Problem Solving (using C)
Topics Introduction to Repetition Structures
Introduction to Computer Science
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
Chapter 13 Conditional Repetition
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Chapter 3 Flow of Control Loops in Java.
CprE 185: Intro to Problem Solving (using C)
Presentation transcript:

FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities

PART 4 Problem Solving

chapter21 ONCE IS NOT ENOUGH Iteration Principles

ITERATION: PLAY IT AGAIN, SAM What is a loop? A loop is a programming structure that provides a means of repeating the same code multiple times. The programmer must control the loop. Copyright © 2003 Pearson Education, Inc.

Classic Loop Problem Instructions on a bottle of shampoo. Lather Rinse Repeat But when does it end? Repeat once, twice, each time we hit repeat? Copyright © 2003 Pearson Education, Inc.

Loop components There are four parts to every loop initialization decision body update Copyright © 2003 Pearson Education, Inc.

Loop control In most loops, there will be one variable that will control the loop. That variable is called the loop control variable. The loop control variable must be initialized and updated. The loop continues until the loop control variable reaches a predefined value. Copyright © 2003 Pearson Education, Inc.

Initialization We set our loop control variable to some beginning value that makes sense for the task. Counting tasks, set the variable to 0 or 1. Copyright © 2003 Pearson Education, Inc.

Update Each time through the loop, the loop control variable may be changed. This change is usually called an increment, but there are many ways to control loops that do not involve an increment. This update must “help” the loop control variable to reach the control value. Copyright © 2003 Pearson Education, Inc.

Decision A decision is like the condition of an if statement. If the condition is true, the loop continues to run. If the condition is false, the loop stops and the statement just beneath the loop executes. Copyright © 2003 Pearson Education, Inc.

Body The action or set of actions that you want to repeat. The body of a loop may include update or it may simply carry out an action. Copyright © 2003 Pearson Education, Inc.

The World Famous Iteration for loop for loops are found in most programming languages a for loop is a counting loop also called a definite loop a for loop contains all four parts of a loop Copyright © 2003 Pearson Education, Inc.

The for Statement – aka counting loop A for statement has the following syntax: The initialization is executed once before the loop begins The statement is executed until the condition becomes false for ( initialization ; condition ; increment ) { statement(s); } The increment portion is executed at the end of each iteration Copyright © 2003 Pearson Education, Inc.

Let’s look at Counter.html Simple counting loop. Copyright © 2003 Pearson Education, Inc.

Let’s look at two loops Counter2.html Copyright © 2003 Pearson Education, Inc.

Loop problems Infinite loop. The loop control variable fails to reach the limit value. Caused by failing to update the loop control variable or failing to have the loop control variable reach the limit. May also occur if you have a value that “skips” over the limit. Demo Copyright © 2003 Pearson Education, Inc.

Off by one error Have your program increment one too many or one too few times. Demo Copyright © 2003 Pearson Education, Inc.