Intro to Computer Science Loops

Slides:



Advertisements
Similar presentations
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Advertisements

CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Repetition Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Loop Statements After reading and studying this Section,
Repetition Statements Recitation – 02/20/2009 CS 180 Department of Computer Science, Purdue University.
Computer Science 1620 Loops.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
CS 117 Spring 2002 Repetition Hanly Chapter 4 Friedman-Koffman Chapter 5.
© 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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
Chapter 6 Iteration Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
Chapter 3 Control Flow Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
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.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
CPS120 Introduction to Computer Science Iteration (Looping)
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
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,
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
CSC 142 I 1 CSC 142 Iterations [Reading: chapter 6]
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
1 Ch. 6 Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit number of times.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
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.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Program Looping Why we need loops in our code –Make code concise for repetitive processes When to use loops –Run a block of code repetitively –Process.
6. Iteration Intro Programming in C++ Computer Science Dept Va Tech August, 2001 © Barnette ND & McQuain WD 1 Iteration pass (or iteration)-one.
COMP Loop Statements Yi Hong May 21, 2015.
CMSC 150 LOOPS CS 150: Fri 20 Jan Representing DNA AGTCCAGTGTCAA.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
While ( number
Loops. More Flow of Control  Sometimes we want to do something many times.  Don’t have to write all the steps out multiple times.  Use a LOOP – control.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
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.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
REPETITION CONTROL STRUCTURE
Repeating the Execution of Statements
Chapter 3: Decisions and Loops
Loops in Java.
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Topic 5 for Loops -Arthur Schopenhauer
Topics discussed in this section:
Lecture 07 More Repetition Richard Gesick.
ITM 352 Flow-Control: Loops
Lecture 4B More Repetition Richard Gesick
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
Outline Altering flow of control Boolean expressions
Structured Program Development in C
Intro to Nested Looping
Topics discussed in this section:
More Looping Structures
What does this do? def revList(L): if len(L) < = 1: return L x = L[0] LR = revList(L[1:]) return LR + x.
Intro to Nested Looping
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
Introduction to Computer Science
More Looping Structures
CS2011 Introduction to Programming I Loop Statements (I)
Introduction to Strings
Presentation transcript:

Intro to Computer Science Loops Dr. Olivera Grujic USC

Loops?

Loops?

Computer Science Loop Control flow statement for specifying iteration, which allows code to be executed repeatedly. https://en.wikipedia.org/wiki/For_loop

While Loop in C++

While Loop in C++

While Loop in C++ Initialization Condition Update

Problem with While Pattern Hard to see all you need to know how the loop progresses Easy to be so engrossed in writing the body of the loop that you forget to increment

For Loop in C++

For Loop in C++ Condition Update Initialization

You Don’t Have to Count Upward!

You Don’t Have to Update by 1!

DoWhile Loop

DoWhile Loop Initialization Update Condition

What Does This Code Print?

Let’s Rewrite Outer Loop to DoWhile

Let’s Rewrite Outer Loop to DoWhile

Code Examples

Loop Through Strings

Verify Phone Number Has 10 Digits

Calculates x to the power of n

Implements “hotPotato” Function takes 2 strings Returns false if both strings are empty If either or both strings are non-empty, swaps the values of strings