Engineering 1020 Introduction to Programming Peter King Winter 2010.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures.
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
How SAS implements structured programming constructs
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
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.
CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Repeating Actions While and For Loops
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Looping Yong Choi School of Business CSU, Bakersfield.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Copyright © Texas Education Agency, Computer Programming For Loops.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
For Loops. Challenge: Racer ● Simulate a race that says “Now on lap X” for 10 laps. ● Make X vary, so it says 1, then 2, then 3 ● Use only one output.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
AEEE 195 – Repetition Structures: Part B Spring semester 2011.
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,
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
Counting Loops.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
February 25,  The BDE(Begin-During-End) event.  Worksheet – Exercise # 9 Instructions  2nd Period Test.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
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.
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.
This is a while loop. The code is done while the condition is true. The code that is done is enclosed in { }. Note that this program has three parts: Housekeeping.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures Lecture 10.
CS161 Introduction to Computer Science
Lecture 7: Repeating a Known Number of Times
Chapter 5: Loops and Files.
Chapter 5: Repetition Structures
Chapter 5: Looping Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Arrays, For loop While loop Do while loop
Iteration with While You can say that again.
Lecture Notes – Week 3 Lecture-2
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
3 Control Statements:.
Repetition Control Structure
Loop Strategies Repetition Playbook.
PROGRAM FLOWCHART Iteration Statements.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Presentation transcript:

Engineering 1020 Introduction to Programming Peter King Winter 2010

ENGI 1020: Loops Before we start, two new operators –Increment → ++ Adds one –Decrement → – Subtracts one int x = 5; x--; // x now equals 4 x++; x++; //x now equals 6

ENGI 1020: Loops Very often programs must do repetitive tasks Loops allow us to define a block of code that will execute from top to bottom and then repeat To prevent the code from running forever, we define a condition that tells the loop to stop We could say “do something while something is true”

ENGI 1020: Loops The while loop –One of 3 types of loops in c++ while is a keyword that indicates the start of a loop It contains a condition that must be true for the loop to repeat

ENGI 1020: Loops Buy Lotto ticket Check ticket Didn't Win Go to workRetire My Retirement Plan

ENGI 1020: Loops Buy Lotto ticket Check ticket Didn't Win Go to workRetire My Retirement Plan

ENGI 1020: Loops Structure is same as if statement while (condition){ Statement … Statement }

ENGI 1020: Loops Structure is same as if statement while (condition){ Statement … Statement } If condition is true, statement(s) are executed If condition remains true, statement(s) are repeated

ENGI 1020: Loops Once again the condition is a logical expressions that will be evaluated to either true or false Multiple conditions can be combined with –&& → and –|| → or

ENGI 1020: Loops Structure examples –Factorial –Babylonian estimate

ENGI 1020: Loops Loop Design –What is the task to be repeated? The general case –When should I stop? Based on a value? Based on a count? –What happens when I'm done?

ENGI 1020: Input Conditioning See online notes*