Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.

Slides:



Advertisements
Similar presentations
Repetition control structures
Advertisements

Repeating Actions While and For Loops
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.
Loops Counting down from N to 1 in assembly we used JUMP statements to repeat previous instructions thus looping READ LOOP: WRITE SUB decrement JPOSLOOP.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 6: Loop Control Structures.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Objectives You should be able to describe:
Chapter 6 - Visual Basic Schneider
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.
5.05 Apply Looping Structures
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Chapter 4: Control Structures II
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 5: Control Structures II (Repetition)
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
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.
ENGR 112 Decision Structures.
Logic Structure - focus on looping Please use speaker notes for additional information!
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.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
Chapter 4 Looping Statements Adapted From: Starting Out with Visual Basic 2008 (Pearson)
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Chapter 4: Control Structures II
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Pascal Programming Iteration (looping) Carl Smith National Certificate Unit 4.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Looping ROBERT REVAES. Logical Operators  && AND  Both have to be true for it to evaluate to be true.  || OR  One or the other has to be true for.
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition)
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Controlling Program Flow with Looping Structures
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Fortran: Control Structures Session Three ICoCSIS.
National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 11.1 Test-Driving the Interest Calculator Application 11.2 Essentials of Counter-Controlled Repetition.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
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.
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.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
UNIT 5 Lesson 15 Looping.
REPETITION CONTROL STRUCTURE
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Programming Logic and Design Fourth Edition, Comprehensive
Lists, Loops, Validation, and More
3rd prep. – 2nd Term MOE Book Questions.
Control Structures - Repetition
حلقات التكرار.
Chapter (3) - Looping Questions.
3.1 Iteration Loops For … To … Next 18/01/2019.
Case & Repetitive Statements
Prepared By: Deborah Becker
Conditional Loops Counted Loops
Chap 7. Advanced Control Statements in Java
Presentation transcript:

Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration in VB programming, requires the use of Looping Constructs There are 2 main types of Looping Constructs: Determinate Loops: will repeat themselves a known (specific) number of times (For..Next Loops) Indeterminate Loops: will repeat themselves an unknown number of times (Do Loops) [Until; While]

Determinate Loops A group of statement is repeated a specific number of times For..Next Loops Repeat the statements in a loop a specific number of times Each For statement has a corresponding Next statement For..Next Loop syntax: For Counter/LoopIndex = Start To End [step step] Statements (Body of Loop) Next Counter/LoopIndex

The For..Next loop uses the For and Next statements and a Counter Variable [LoopIndex] The elements of a For..Next: The Counter/LoopIndex must be a numeric variable, determines the number of times the statements inside the loop will be executed Start and End may be Constants, Variables, Numeric Property Values, or Numeric Expressions, and further determine the initial and final value of the counter The optional word Step may be included, along with the value to be added to the LoopIndex (positive/negative) for each iteration of the loop, and if omitted, the default value is 1 for each increment of the loop

Dim iLoopIndex As Integer Dim iMaximum As Integer iMaximum = Inputbox(“Enter the value”, Number of Entries) For iLoopIndex = 0 To iMaximum ‘The statements inside of the loop are indented, and referred to as ‘the body of the loop Next iLoopIndex

A Counter-Controlled Loop generally has 3 elements: Initialise the Counter Increment the Counter [step] Test the Counter to determine when it is time to Terminate the loop For iIndex = 2 To 100 Step 2 will count from 2 to 100 by 2 The statements in the body of the loop will be executed 50 times, with iIndex = 2, 4, 6, …. The program checks for greater than the test value and not equal to

Exiting For..Next Loops If you enter an Endless Loop, the program execution will have to be broken manually Therefore, you will need to enter Break Time Ctrl + Break With For..Next loops, you may need to terminate the loop before the loop index reaches its final value VB provides an Exit For statement for this situation Generally, an Exit For statement is part of an If statement

For iLoopIndex = 1 To 10 If txtInput.Text = “ ” Then ‘nothing was entered into the input textbox MsgBox “You must enter something” Exit For End If ………. ………. ‘statements in the loop Next iLoopIndex