Nate Brunelle Today: Repetition, Repetition

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
CS0004: Introduction to Programming Repetition – Do Loops.
1 Repetition structures Overview while statement for statement do while statement.
ECS15 for and sequence. Comments  Another way to repeat.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Week 11 Recap CSE 115 Spring Want to write a programming language? You’ll need three things: You’ll need three things: –Sequencing –Selection Polymorphism.
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.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Using Shortcut Arithmetic Operators Accumulator: A variable that is used to total. Its value is repeatedly increased by some amount. Java provides shortcuts.
Quiz Answers 1. Show the output from the following code fragment: int a = 5, b = 2, c = 3; cout
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Chapter 6 Looping CS185/09 - Introduction to Programming Caldwell College.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
For loops in programming Assumes you have seen assignment statements and print statements.
CS – 1P Using Electronic Voting System (EVS) questioning in the Instructional Design for CS-1P.
Repetition and Iteration ANSI-C. Repetition We need a control instruction to allows us to execute an statement or a set of statements as many times as.
Loops & List Intro2CS – week 3 1. Loops -- Motivation Sometimes we want to repeat a certain set of instructions more than once. The number of repetitions.
A: A: double “4” A: “34” 4.
Expressions Methods if else Statements Loops Potpourri.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
FOP: While Loops.
Trace Tables In today’s lesson we will look at:
Chapter 4 Repetition Statements (loops)
Lecture 6 Repetition Richard Gesick.
The switch Statement, and Introduction to Looping
CS161 Introduction to Computer Science
Lesson 05: Iterations Class Chat: Attendance: Participation
Iterations Programming Condition Controlled Loops (WHILE Loop)
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.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
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
Loops October 10, 2017.
Iteration with While You can say that again.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CMSC 120: Visualizing Information 3/25/08
Outline Altering flow of control Boolean expressions
Nate Brunelle Today: Repetition, A Trip To The Moon
Nate Brunelle Today: Slicing, Debugging, Style
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Repetition In today’s lesson we will look at:
3.1 Iteration Loops For … To … Next 18/01/2019.
Loop Strategies Repetition Playbook.
Nate Brunelle Today: Dictionaries
Loops.
For Loops (Iteration 1) Programming Guides.
More Repetition While and For loop variations
CS1110 Today: collections.
Nate Brunelle Today: Strings, Type Casting
For loops Taken from notes by Dr. Neil Moore
Nate Brunelle Today: Conditional Decision Statements
Repetition Statements
PROGRAM FLOWCHART Iteration Statements.
Topic: Loops Loops Idea While Loop Introduction to ranges For Loop
Nate Brunelle Today: Dictionaries
Nate Brunelle Today: Conditional Decision Statements
Gavin Restifo March 1, 2019 Today: Repetition Part 2 - For Loops
Nate Brunelle Today: Style, Collections
Nate Brunelle Today: Strings, Type Casting
While Loops in Python.
Presentation transcript:

Nate Brunelle Today: Repetition, Repetition CS1110 Nate Brunelle Today: Repetition, Repetition

Questions?

Last Time While loops For loops

“While” Loops while loop Keep repeating until the boolean expression is False “so long as this is True, keep doing the action” Guard Condition while boolean expression: action1 action2 Body/ Inside

Rules for While Loops Some aspect of the Guard Condition must change in the body It must change in a way such that it will eventually become false Note: The guard is checked at the end

“for” Loops For loop for [variable v] in [collection]: action Do the action a certain number of times “do the action once per each thing in here” The variable takes the value of each thing in the collection in order for [variable v] in [collection]: action for i in range(5): print(‘hi’) Range(5) -> [0,1,2,3,4]

Collections Order doesn’t matter, No Repetition Order Matters, Repetition ok Examples: String List Tuple Range Counting starts at 0 collection[index] gives a specific value in the collection Order doesn’t matter, No Repetition Examples: Set Dict

Range range(x) range(x,y) Gives all integers from 0 (inclusive) to x (exclusive) range(5) -> 0,1,2,3,4 range(x,y) Gives all integers from x (inclusive) to y (exclusive) Range (2, 6) -> 2,3,4,5 [lower, upper)

hello Strings Collection of characters Order Matters Repetition ok X = “hello” X[0] -> h hello 1 2 3 4 Indices

Which kind of loop? I know condition to stop repeating I know the number of times I want to repeat I want to repeat once per thing in a collection