For Next Looping My first Looping Structure. For…Next FOR counter_variable = initial_value TO end_value STEP increment Statement-1 Statement-2 ……. Statement-n.

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
CS0004: Introduction to Programming Repetition – Do Loops.
Chapter 4. Loops and Character Manipulation Loops in FORTRAN are constructs that permits us to execute a sequence of statements more than once. Type of.
Repeating Actions While and For Loops
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Faculty of Sciences and Social Sciences HOPE Java: Loops within loops Stewart Blakeway FML 213
Do Loop The syntax of DO loop: DO variable = initial_value, final_value[, increment] [statements] END DO Example: PROGRAM LINES ! Illustration of DO-loops.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Loops – While, Do, For Repetition Statements Introduction to Arrays
CHAPTER 6 REPETITIVE EXECUTION 6.1 Introduction A repetition structure or loop makes possible the repeated execution of one or more statements called the.
BACS 287 Programming Fundamentals 4. BACS 287 Programming Fundamentals This lecture introduces the following iteration control structure topics: – Do.
27 March, 2000 CS1001 Lecture 9 Lab 2 Complete Lecture 8 DO Loops –Counter-controlled DO loop –Depreciation example -- details –Nested loops –Examples.
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.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
1 Python Chapter 4 Branching statements and loops © Samuel Marateck 2010.
1 Principles of Software Design and Development LOOPS / REPITITION.
MULTIPLES OF 2 By Preston, Lincoln and Blake. 2 X 1 =2 XX 2X1=2 1+1=2.
Iteration Conditional Loops Counted Loops. Charting the Flow of Control We’ve used flow charts to visualise the flow of control. The simplest form 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.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
5.05 Apply Looping Structures
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.
PL/SQL Loops. Building Logical Conditions All logical conditions must yield a boolean condition. You can build a simple Boolean condition by combining.
Divide by 8 page – groups of 8 Division Sentence 0 ÷ 8 = 0.
Repetition Chapter 7. Overview u For Loop u Do Loop  Do While Loop  Do Until Loop  Do Loop While  Do Loop Until u Nested Loops.
ISAT 252 Visual Basic Repetition. Assignment Should have read Chapter 5 ( ) on loops Do tutorial 5-4.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Chapter 71 Repetition - Do Loops n A Loops, is used to repeat a sequence of statements a number of time n There are two loops commands in Visual Basic.
Chapter 4 Looping Statements Adapted From: Starting Out with Visual Basic 2008 (Pearson)
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
6.2 For…Next Loops General Form of a For…Next Loop
Counting Loops.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 5 Repetition.
For Loop Tips And Tricks
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Controlling Program Flow with Looping Structures
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 11.1 Test-Driving the Interest Calculator Application 11.2 Essentials of Counter-Controlled Repetition.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
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 ISYS 350. Write a Program that asks user to enter any numbers and displays the largest number Process: Largest = the first number Get the next number.
Chapter 5 - VB 2008 by Schneider1 Chapter 5 – Repetition 5.1 Do Loops 5.2 Processing Lists of Data with Do Loops 5.3 For...Next Loops.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
CHAPTER 4 DECISIONS & LOOPS
EasyCode Foundations Vocabulary Terms.
Chapter 3: Decisions and Loops
Problem Solving and Control Statements: Part 2
Lists, Loops, Validation, and More
Chapter 5 Repetition.
Repetition and Loop Statements
Outline Altering flow of control Boolean expressions
Count Controlled Loops (Nested)
Chapter (3) - Looping Questions.
For loops intCount = 1 inCount = intCount + 1 True intCount
Case & Repetitive Statements
Loop Construct.
Vocabulary Memory Cards--Sample
Prepared By: Deborah Becker
ASP control structure BRANCHING STATEMENTS
Conditional Loops Counted Loops
Repetition (While Loop) LAB 9
For...Next Statements.
Presentation transcript:

For Next Looping My first Looping Structure

For…Next FOR counter_variable = initial_value TO end_value STEP increment Statement-1 Statement-2 ……. Statement-n NEXT counter_variable

For…Next

For…Next You use For...Next statements to execute a block of statements a specific number of times. For loops use a counter variable whose value is increased or decreased with each repetition of the loop.

For…Next Part of the structure Index or counter Starting value Ending value Next (increments counter) Iteration (one execution of the statement inside the loop)

Action of For...Next structure Deterministic loop For i = start To end statement1 statement2... I <=ending value i >ending value Next (i) For i = start To end statement1 statement2... Next (i) statement Increment counter Here

For Next Loops deterministic Repeats a statement OR a group of statements a specified number of times Dim intStoreNumber As Integer For intStoreNumber = 1 To 20 ' Check the order ' Fetch correct order ' Carry back Stales Next intStoreNumber

For…Next with Step Dim intStoreNumber As Integer For intStoreNumber = 1 To 19 Step 2 ' Check the order ' Fetch correct order ' Carry back empties Print intStoreNumber Next (increments counter by the step) How many times will this loop execute?

Simple loop Dim x as integer, _ var1 as string, _ var2 as string, _ var3 as string For x = 1 To 50 input #1, var1,var2,var3 Call PrintData(var1,var2) Next x

Step Increments You can increase or decrease the counter variable by a value other than 1 by using the Step keyword. Example Dim intCounter as integer, _ intTotal as integer For intCounter = 2 To 10 Step 2 intTotal = intTotal + intCounter Next intCounter Is intTotal a counter or accumulator?

Nesting: What is the Outcome Dim Outer as integer, Inner as integer For Outer = 1 To 8 Print Outer; For Inner = 1 To Outer Print "X "; Next Inner Print Next Outer

Outcome of the loop 1 X 2 XX 3 XXX 4 XXXX 5 XXXXX 6 XXXXXX 7 XXXXXXX 8 XXXXXXXX