Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.

Slides:



Advertisements
Similar presentations
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
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.
Iteration Statements Lather Rinse Repeat. Three Iteration Statements For Each For Next While.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
BACS 287 Programming Fundamentals 4. BACS 287 Programming Fundamentals This lecture introduces the following iteration control structure topics: – Do.
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.
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.
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
Dani Vainstein1 VBScript Session 9. Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables,
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
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.
Chapter 12: How Long Can This Go On?
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control 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.
ME 142 Engineering Computation I Loops. Key Concepts Looping Basics For… Next Statement Do… Loop Statement For Each… Next Statement.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
ISAT 252 Visual Basic Repetition. Assignment Should have read Chapter 5 ( ) on loops Do tutorial 5-4.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
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.
Tutorial 6 The Repetition Structure
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
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
Introduction to Problem Solving and Control Statements.
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.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
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.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Controlling Program Flow with Looping Structures
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
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.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
CSET 3250 Client-Side Scripting VBScript : Operators, Control Structures, Procedures and Functions.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
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.
Chapter 6 - VB 2008 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study: Analyze a Loan.
UNIT 5 Lesson 15 Looping.
Chapter 5- Control Structures: Part 2
Visual Basic 6 (VB6) Data Types, And Operators
Problem Solving and Control Statements: Part 2
Development of Internet Application 1501CT - Sara Almudauh
Lecture 07 More Repetition Richard Gesick.
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Lecture 4B More Repetition Richard Gesick
VBScript Session 4 Dani Vainstein.
VBScript Session 6 Dani Vainstein.
Iteration: Beyond the Basic PERFORM
VBScript Session 7 Dani Vainstein.
Case & Repetitive Statements
Chapter 6 - VB.Net by Schneider
Prepared By: Deborah Becker
ASP control structure BRANCHING STATEMENTS
Conditional Loops Counted Loops
Quick Test Professional Training Part 1
Presentation transcript:

Dani Vainstein1 VBScript Session 5

Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using Select Case

Dani Vainstein3 Subjects for session 5 Looping through code. Do … Loop While … Wend For … Next For … Each Exit statement.

Dani Vainstein4 Looping Through Code Looping allows you to run a group of statements repeatedly. Some loops repeat statements until a condition is False; others repeat statements until a condition is True. There are also loops that repeat statements a specific number of times.

Dani Vainstein5 Do While/Until

Dani Vainstein6 Looping Through Code Using Do…Loop Statement Repeats a block of statements while a condition is True or until a condition becomes True. The following looping statements are available in VBScript: Do [{While | Until} condition] [statements] [Exit Do] [statements] Loop Do [{While | Until} condition] [statements] [Exit Do] [statements] Loop Do [statements] [Exit Do] [statements] Loop [{While | Until} condition] Do [statements] [Exit Do] [statements] Loop [{While | Until} condition]

Dani Vainstein7 Looping Through Code Using Do…Loop Statement You can exit a Do...Loop by using the Exit Do statement. Because you usually want to exit only in certain situations, such as to avoid an endless loop, you should use the Exit Do statement in the True statement block of an If...Then...Else statement. If the condition is False, the loop runs as usual.

Dani Vainstein8 Looping Through Code Using Do…Loop Statement Dim bCheck, Count bCheck = True : iCount = 0 ' Initialize variables. Do ' Outer loop. Do While iCount < 20 ' Inner loop. iCount = iCount + 1 ' Increment Counter. If iCount = 10 Then ' If condition is True... bCheck = False ' set value of flag to False. Exit Do ' Exit inner loop. End If Loop Loop Until bCheck = False ' Exit outer loop immediately.

Dani Vainstein9 Looping Through Code Using While…Wend Statement Executes a series of statements as long as a given condition is True. The While...Wend statement is provided in VBScript for those who are familiar with its usage. However, because of the lack of flexibility in While...Wend, it is recommended that you use Do...Loop instead. The While...Wend statement is provided in VBScript for those who are familiar with its usage.

Dani Vainstein10 Looping Through Code Using For…Next Statement Repeats a group of statements a specified number of times. You can use For...Next statements to run a block of statements a specific number of times. For loops, use a counter variable whose value increases or decreases with each repetition of the loop Dim x For x = 1 To 50 MyProc Next

Dani Vainstein11 Looping Through Code Using For…Next Statement Using the Step keyword, you can increase or decrease the counter variable by the value you specify. In the following example, the counter variable j is incremented by 2 each time the loop repeats. When the loop is finished, the total is the sum of 2, 4, 6, 8, and 10. Dim j, itotal For j = 2 To 10 Step 2 itotal = itotal + j Next Msg = "The total is " & itotal

Dani Vainstein12 Looping Through Code Using For…Next Statement You can exit any For...Next statement before the counter reaches its end value by using the Exit For statement. Because you usually want to exit only in certain situations, such as when an error occurs, you should use the Exit For statement in the True statement block of an If...Then...Else statement. If the condition is False, the loop runs as usual.

Dani Vainstein13 Looping Through Code Using For Each...Next Statement A For Each...Next loop is similar to a For...Next loop. Instead of repeating the statements a specified number of times, a For Each...Next loop repeats a group of statements for each item in a collection of objects or for each element of an array. This is especially helpful if you don't know how many elements are in a collection.

Dani Vainstein14 Looping Through Code Exit Statement Exits a block of Do...Loop, For...Next, Function, or Sub code. Exit Do Provides a way to exit a Do...Loop statement. It can be used only inside a Do...Loop statement. Exit For Provides a way to exit a For loop. It can be used only in a For...Next or For Each...Next loop. Exit Function Immediately exits the Function procedure in which it appears. Exit Property Immediately exits the Property procedure in which it appears. Exit Sub Immediately exits the Sub procedure in which it appears.

Dani Vainstein15 Excercises

Dani Vainstein16 Lab 5.1 Input parameters names are From and To Assume that both inputs are integers. Display in reporter all the pairs between For and To Use the For...Next loop. Tip Use the Step statement. Concatenate to a temporary string. Try your program for the following values From = 2 : To = 10 (2,4,6,8,10) From = 1 : To = 9 (2,4,6,8) From = -7 : To = 3 (-6,-4,-2,0,2) From = 50 : To = 41 (50,48,46,44,42) From = -3 : To = -9 (-4,-6,-8)

Dani Vainstein17 Lab 5.2 Input parameters names are Pswd. Declare a constant MY_PASSWORD. Declare a constant MAX_RETRY = 3. If the password is correct display a micPass message. If the password is typed wrong more then MAX_RETRY times, display a micFail message. Use the Do..Loop (While or Until). Tip Use the Exit Loop statement.

Make sure to visit us Tutorials Articles Projects And much more 18