For Loops (Iteration 1) Programming Guides.

Slides:



Advertisements
Similar presentations
Iteration While / until/ for loop. Iteration: while/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initalise.
Advertisements

Introduction to Computing Science and Programming I
CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
Announcements The first graded lab will be posted Sunday 2/15 and due Friday 2/27 at midnight It is brand new, so please don’t hand in last semester’s.
CS 240: Data Structures Tuesday, June 5 th Programming Semantics, Software Life Cycle.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 7: Program flow control.
Copyright © Texas Education Agency, Computer Programming For Loops.
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
Simple Python Loops Sec 9-7 Web Design.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
Control Structures FOR Statement Looping.
CPS120 Introduction to Computer Science Iteration (Looping)
For loops in programming Assumes you have seen assignment statements and print statements.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Repetition Statements while and do while loops
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
CPS120 Introduction to Computer Science Iteration (Looping)
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
GCSE Computing: Programming GCSE Programming Remembering Python.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
BO65: PROGRAMMING ITERATION 1. Starter  Write down what you think the code below outputs on screen: Dim intCounter as integer intCounter = 0 Do while.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
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.
FOP: While Loops.
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
Trace Tables In today’s lesson we will look at:
REPETITION CONTROL STRUCTURE
Python Loops and Iteration
Think What will be the output?
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
While Loops in Python.
Iterations Programming Condition Controlled Loops (WHILE Loop)
While Loops (Iteration 2)
Writing Functions( ) (Part 5)
Writing Functions( ) (Part 5)
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
File Handling Programming Guides.
Introduction to pseudocode
Functions and Procedures
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Nate Brunelle Today: Repetition, Repetition
Data Structures – 1D Lists
Looping and Random Numbers
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
Coding Concepts (Basics)
LOOPS BY: LAUREN & ROMEO.
Repetition Structures
Module 4 Loops.
CMSC201 Computer Science I for Majors Lecture 09 – While Loops
Repetition In today’s lesson we will look at:
3.1 Iteration Loops For … To … Next 18/01/2019.
Inputs and Variables Programming Guides.
Flowcharts and Pseudo Code
A LESSON IN LOOPING What is a loop?
CPS125 Week
Chapter 4: Repetition Structures: Looping
For Loops Pages
While Loops in Python.
How to allow the program to know when to stop a loop.
Presentation transcript:

For Loops (Iteration 1) Programming Guides

For Loops (Iteration 1) Iterations in Python The word iterate mean loop. Iterations are therefore loops and in the python language there are two types of loop. For Loops These are count controlled (they run for a set number of times) While Loops These are condition controlled (they run forever – or until a certain condition is met)

For Loops (Iteration 1) ‘For Loops’ in Python For Loops are set up using the following statement: for x in range (n): Lets take a look more closely…

For Loops (Iteration 1) ‘For Loops’ in Python for x in range (n): The x is simply a variable. It could have any name. It is however a special kind of variable known as a ‘stepper’ We must finish the statement with a colon The n is simply representing a number that we want the loop to repeat itself for. If there was a 5 in the brackets, the loop would repeat 5 times.

For Loops (Iteration 1) ‘For Loops’ in Python for x in range (5): print(“Hello World ”, x) 5 4 1 2 3 Hello Word 0 Hello Word 1 Hello Word 2 Remember: In programming, we count from zero. So our stepper variable begins as a ‘0’. In this case, as soon as the variable becomes 5, the loop ends. Hello Word 3 Hello Word 4

For Loops in Python for x in range (m,n,o): ‘For Loops’ in Python There are some other tools that we can use to customise our For Loop. We can change the starting number of our loop. We can state the steps we want to go up in (it doesn’t have to go up in 1s) Steps to move up in Starting Number Upper limit number – what the loop will stop at

For Loops in Python ‘For Loops’ in Python – An Example Here is a simple example of a FOR loop being used to display the numbers 1 – 10. Here, the stepper variable is being used to output the number. Because the stepper starts at 0, 1 has been added on to the variable at the moment that it is being outputted to the screen.