PROGRAMMING ITERATION 2. Starter  Put the following code in order (write down the line numbers).  The program should display the numbers 1-24 on screen.

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

Solving Problems with Repetition. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C# program Correctly.
Programming in python Lesson 2.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
Computer Science 1620 Loops.
CS100J October 07, 2003 Loops Repetitive statements, or iterative statements, or loops “O! Thou hast damnable iteration and art, indeed, able to corrupt.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Introducing Loop Statements Liang, pages Loop statements control repeated execution of a block of statements Each time the statements in the block.
Loops – While, Do, For Repetition Statements Introduction to Arrays
More loops Linag, Chpt 3, pp The do-loop continue- condition ? loop-body statements next statement false true WHILE-LOOP continue- condition? loop-body.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 6: Loop Control Structures.
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.
Copyright © Texas Education Agency, Computer Programming For Loops.
PROGRAMMING In Lesson 5. RECAP  Complete the starter activity.
New ways of learning week Sign up at: Monday 25 th November Tuesday 26 th November Wednesday 27 th November Thursday.
110-K1 Iterations (1) Up to now, need to call the procedure again (e.g. click again on a command button) To repeat a piece of code: Can also use loops:
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Chapter 12: How Long Can This Go On?
Python Programming Chapter 6: Iteration Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
CPS120 Introduction to Computer Science Iteration (Looping)
Visual Basic CODE. Basics of Code Declaration Declaration Set aside a named place to put things Set aside a named place to put things Assignment Assignment.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
MAT 4725 Numerical Analysis Section 1.4 Loops with “do” statements
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
B065: PROGRAMMING Sub Procedures I. Starter  Identify the separate tasks to be performed in the programming task below (break it down into numbered sections).
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
Developing Software Applications Iteration in Visual Basic (Loops)
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
BO65: PROGRAMMING ITERATION 1. Starter  Write down what you think the code below outputs on screen: Dim intCounter as integer intCounter = 0 Do while.
National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.
Solving Problems with Repetition Version 1.0. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C#
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Learning Javascript From Mr Saem
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 Controlling Program Flow with Looping Structures.
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.
Week 3.  TO PRINT NUMBERS FROM 1 TO 20  TO PRINT EVEN NUMBERS FROM 1 TO 20 2.
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.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
CE En 270 Brigham Young University Norm Jones
REPETITION CONTROL STRUCTURE
Think What will be the output?
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Introducing Do While & Do Until Loops & Repetition Statements
Outline Altering flow of control Boolean expressions
Programming In Lesson 3.
Chapter (3) - Looping Questions.
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
PROGRAMMING Sub Procedures I.
3.1 Iteration Loops For … To … Next 18/01/2019.
A LESSON IN LOOPING What is a loop?
Introduction to Repetition
Introduction to Repetition
Database Programming Using Oracle 11g
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
Presentation transcript:

PROGRAMMING ITERATION 2

Starter  Put the following code in order (write down the line numbers).  The program should display the numbers 1-24 on screen. 1.Console.writeline(pos) 2.Pos = pos Pos = 1 4.Loop 5.Do while pos < 25 6.Dim pos as integer Answer: 6, 3, 5, 1, 2, 4

Objectives Understand what is meant by iteration in programming. Explore different types of iteration: DO loops and FOR loops. Understand the use of iteration in programming.

Recap: What is Iteration? Iteration is simply the repetition of a sequence of (one or more) statements. In programming, this is often referred to as a loop. The statements might not be executed at all (zero repetitions), or may be executed at least once. Eventually, something must stop the repetition, allowing the program to continue further.

I know the number of iterations! The good thing about DO loops is that you do not need to know how many times you need to loop. But what if you do know? What if you know you need to loop through code a fixed number of times (e.g. 10?) To do this, you can use a FOR loop. The basic syntax is: For controlvar = startval To endval statement(s) Next controlvar Animated FOR explanation. Let’s loop at a couple of coded examples.

What if you want to step in different values? What if you don’t always want to go up in 1’s? E.g. What if you wanted to print the odd numbers in 1-9. You would need to go up in 2’s! To do this, you just add the STEP keyword into your FOR declaration. For controlvar = startval To endval Step stepval statement(s) Next controlvar Again, let’s go back and look at some coded examples.

Today’s Task Have a go at the For Loop worksheet on the intranet.

Objectives Understand what is meant by iteration in programming. Explore different types of iteration: DO loops and FOR loops. Understand the use of iteration in programming.

Plenary Let’s go through your programming tasks. Explain the difference between: – FOR LOOPS – FOR..STEP LOOPS – DO…LOOPS – When would you use each of the above?