CS 1111 Introduction to Programming Spring 2019

Slides:



Advertisements
Similar presentations
Nested Loops and the Break Statement. What are Nested Loops? Nested loops are: Loops which run inside another loop When would you use nested loops? Performing.
Advertisements

CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Genome Sciences 373 Genome Informatics Quiz Section 3 April 14, 2015.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 6, 2005.
COMP 14 Introduction to Programming Miguel A. Otaduy May 21, 2004.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
Nested Loops. Nesting Control Structures One if statement inside another one An if statement inside a loop A loop inside an if statement Control structures.
There are two additional statements that can be used to control the operation of while loops and for loops: break statements continue statements.
Last Week Doctests Lists List methods Nested Lists Aliasing.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Control Structures FOR Statement Looping.
CPS120 Introduction to Computer Science Iteration (Looping)
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
CS 100 Introduction to Computing Seminar October 7, 2015.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 5 Repetition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
CS 161 Introduction to Programming and Problem Solving Chapter 18 Control Flow Through C++ Program Herbert G. Mayer, PSU Status 10/8/2014 Initial content.
9. ITERATIONS AND LOOP STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Loops (While and For) CSE 1310 – Introduction to Computers and Programming 1.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
Loop. 3.1Introduction to Repetition Structures Loop – a block of code that, under certain conditions will be executed repeatedly. Do Prompt for and input.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
More about Iteration Victor Norman CS104. Reading Quiz.
Loops Upsorn Praphamontripong CS 1110 Introduction to Programming
For loops Genome 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble.
Chapter 3: Decisions and Loops
Topics Introduction to Repetition Structures
Python: Control Structures
Think What will be the output?
Chapter 5: Repetition Structures
Topics Introduction to Repetition Structures
The Linux Command Line Chapter 29
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.
Repetition and Loop Statements
Alice in Action with Java
For loops Genome 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble Notes for 2010: I skipped slide 10. This is.
Outline Altering flow of control Boolean expressions
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
for, do-while and switch statments
Chapter 8: More on the Repetition Structure
CS2011 Introduction to Programming I Loop Statements (II)
Let’s all Repeat Together
CS150 Introduction to Computer Science 1
Introduction to Repetition Structures
CS 1111 Introduction to Programming Spring 2019
Program Flow.
ECE 103 Engineering Programming Chapter 20 Change in Flow of Control
Topics Introduction to Repetition Structures
Introduction to Computer Science
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
For Loops Pages
Topic: Loops Loops Idea While Loop Introduction to ranges For Loop
CSE 231 Lab 2.
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
LOOP Basics.
Introduction to Python
Presentation transcript:

CS 1111 Introduction to Programming Spring 2019 More Loops CS 1111 Introduction to Programming Spring 2019 [The Coder’s Apprentice, §7]

Loops in Python while loop – a condition-controlled loop for loop using the in operator with a list for loop using the range operator – a count-controlled loop Nested loops

While Loop vs. For Loop while <condition>: <statements> <handler> To break the condition such that the loop terminates for <iterate_var> in <collection>: <statements> for <iterate_var> in range(start, stop, step): <statements> default = 1 Iterate up to (or down to) this but not include

While Loop vs. For Loop While loop For loop Use when you don’t know the number of iterations Need to explicitly handle the termination Use when you know the number of iterations Loop stops as it reaches the end of range, or the end of list i = 5 while i > 0: print(i * i * i) i -= 1 for i in range(5, 0, -1): print(i * i * i)

Nested Loops outer loop <condition>: inner loop <condition>: <statements> <handler> Nest with while loops, for loops, or mix while loops and for loops break and continue may be used to handle the flow of execution break and continue are unnecessary with proper loop conditions

Summary Must know (based on exam2 topic list, as of 03/04/2019) while loop for loop Using loops with collections range(end) range(start, end) range(start, end, step) Nested loop Using nested loop with collections