For...Next Statements.

Slides:



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

Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Loops – While, Do, For Repetition Statements Introduction to Arrays
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
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.
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.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
CHAPTER SIX LOOPS © Prepared By: Razif Razali 1. FORMAT OR REFRESH!! WHAT HAVE WE LEARN? Differentiate between the types of selection structure? Which.
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.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.
6.2 For…Next Loops General Form of a For…Next Loop
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Repetition Structures
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Chapter six exercises
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Chapter81 For....Next Loops n For i = m To n statement (s) Next i n For statement designates a numeric variable, called control variable. n It is initialized.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
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.
UCT Department of Computer Science Computer Science 1015F Iteration
Introduction to Programming Lecture 2
Review 1.
Chapter 5- Control Structures: Part 2
Problem Solving and Control Statements: Part 2
Chapter 5: Control Structures II
Lists, Loops, Validation, and More
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
JavaScript: Functions.
Chapter 2.2 Control Structures (Iteration)
Chapter 8: Control Structures
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Looping.
Arrays, For loop While loop Do while loop
CSS161: Fundamentals of Computing
Java - Data Types, Variables, and Arrays
Structured Program Development in C
Iteration: Beyond the Basic PERFORM
Control Statements Loops.
Repetition Control Structure
Problem Solving and Control Statements
Arrays.
SELECTIONS STATEMENTS
Case & Repetitive Statements
Alternate Version of STARTING OUT WITH C++ 4th Edition
Chapter 6 - VB.Net by Schneider
CIS16 Application Development and Programming using Visual Basic.net
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
Control Statements Loops.
Conditional Loops Counted Loops
Database Programming Using Oracle 11g
Presentation transcript:

For...Next Statements

For...Next Syntax Repeats a group of statements a specified number of times. For counter = start To end [Step step] [statements] [Exit For] Next [counter] The counter can't be a Boolean or an array element. The step argument can be either positive or negative. After all statements in the loop have executed, step is added to counter. Any number of Exit For statements may be placed anywhere in the loop as an alternate way to exit. Exit For is often used after evaluating of some condition, for example If...Then, and transfers control to the statement immediately following Next.

For...Next Statement When the number of times a loop should be executed is known in advance, a For…Next loop should be used. For i = m To n statement(s) Next i control variable (counter) initial value terminating value body

For…Next Example Private Sub cmdDisplay_Click() Dim i As Integer 'Display a row of 10 stars picOutput.Cls For i = 1 To 10 picOutput.Print "*"; Next i End Sub

For…Next Example Private Sub cmdDisplay_Click() Dim sum As Single, num As Integer sum = 0 For num = 1 To 99 Step 2 sum = sum + num Next num picOutput.Print "The sum is"; sum End Sub The subroutine calculates the sum of the odd numbers from 1 through 99.

Private Sub cmdReverse_Click() Dim m As Integer, j As Integer Dim temp As String, strWord as String m = Len(txtWord.Text) strWord = txtWord.Text temp = "" For j = m To 1 Step -1 temp = temp & Mid(strWord, j, 1) Next j picTranspose.Print temp End Sub

Nested For...Next Example Private Sub cmdDisplay_Click() Dim Words, Chars As Integer Dim MyString As String MyString = “” For Words = 10 To 1 Step -1 For Chars = 0 To 9 MyString = MyString & Chars Next Chars MyString = MyString & “ ” Next Words picOutput.Print MyString End Sub This example uses the For...Next statement to create a string that contains 10 instances of the numbers 0 through 9, each string separated from the other by a single space. The outer loop uses a loop counter variable that is decremented each time through the loop.

Private Sub cmdDisplay_Click() Dim j As Integer, k As Integer picTable.Cls For j = 1 To 4 For k = 1 To 4 picTable.Print j; "x"; k; "="; j * k, Next k picTable.Print Next j End Sub