Public Class Form1 Inherits System.Windows.Forms.Form Private Sub bntRedDemo_Click(…. Sleep(5000) bntRedDemo.Text = "You waited 5 seconds for this?" End.

Slides:



Advertisements
Similar presentations
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Advertisements

Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
instance variables property procedures for the mintQuantity instance variable.
Private Sub bntRedDemo_Click(…. Dim intTheOnes As Integer For intTheOnes = 0 To 9 bntRedDemo.Text = intTheOnes.ToString bntRedDemo.Refresh() Sleep(100)
CSI 101 Elements of Computing Spring 2009 Lecture # 8 Looping and Recursion Wednesday, February 25 th, 2009.
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.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
What is the best way to start? 1.Plug in n = 1. 2.Factor 6n 2 + 5n Let n be an integer. 4.Let n be an odd integer. 5.Let 6n 2 + 5n + 4 be an odd.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Chapter 5: Control Structures II (Repetition)
5.05 Apply Looping Structures
Objective: Learn to multiply and divide integers.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
For Loops. Challenge: Racer ● Simulate a race that says “Now on lap X” for 10 laps. ● Make X vary, so it says 1, then 2, then 3 ● Use only one output.
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.
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
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.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
ENGR 112 Decision Structures.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
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.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
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 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
Tutorial 6 The Repetition Structure
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.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
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.
Chapter 05 (Part III) Control Statements: Part II.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Chapter 5: Control Structures II
Count and add list of numbers From user input and from file.
6.2 For…Next Loops General Form of a For…Next Loop
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 © Curt Hill Loop Types and Construction Logical types and construction hints.
Chapter 8 P 1 Arrays and Grids Single-dimension arrays Definition An array is a sequence of elements all referred to with a common name. Other terms: table,
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Controlling Program Flow with Looping Structures
5b – For Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
CMSC 150 LOOPS CS 150: Fri 20 Jan Representing DNA AGTCCAGTGTCAA.
 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. ◦
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Loops ( while and for ) CSE 1310 – Introduction to Computers and Programming Alexandra Stefan 1.
CS 536 © CS 536 Spring Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 15.
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.
CE En 270 Brigham Young University Norm Jones
UNIT 5 Lesson 15 Looping.
Introduction To Repetition The for loop
Visual Basic 6 (VB6) Data Types, And Operators
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Chapter 5 – Control Structures: Part 2
Introducing Do While & Do Until Loops & Repetition Statements
Unit 2 Programming.
Structured Program Development in C
Chapter (3) - Looping Questions.
Algorithm Discovery and Design
Do … Loop Until (condition is true)
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
For...Next Statements.
Database Programming Using Oracle 11g
Presentation transcript:

Public Class Form1 Inherits System.Windows.Forms.Form Private Sub bntRedDemo_Click(…. Sleep(5000) bntRedDemo.Text = "You waited 5 seconds for this?" End Sub Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) End Class Windows From Designer generated code After 5 Seconds

Sleep(5000) ‘Pause for 5 seconds Sleep(1000) ‘Pause for 1 second Sleep(500) ‘Pause for 1/2 second

The For loop is very versatile with lots of options. The following is the syntax: For LoopCounter = InitialValue To TerminatingValue Program Statement(s) Next LoopCounter For LoopCounter = InitialValue To TerminatingValue Program Statement(s) Next LoopCounter The sequence for the correct evaluation of a For loop is as follows: 1 The LoopCounter is set to the value InitialValue. 2 The LoopCounter is compared to the TerminatingValue. If the LoopCounter is greater than the TerminatingValue, go to step 6. Otherwise, continue with the execution of the loop. 3 The program statements contained in the body of the loop are executed. 4 The value LoopCounter is incremented. 5 Go to step 2. 6 Exit the loop.

Private Sub bntRedDemo_Click(…. Dim intCounter As Integer intCounter = 0 For intCounter = 1 To 5 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) Next intCounter End Sub …

Private Sub bntRedDemo_Click(…. Dim intCounter As Integer intCounter = 0 For intCounter = 1 To 47 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) Next intCounter End Sub …

Private Sub bntRedDemo_Click(…. Dim intCounter As Integer intCounter = 0 For intCounter = 11 To 47 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) Next intCounter End Sub …

Private Sub bntRedDemo_Click(…. Dim intCounter As Integer intCounter = 0 For intCounter = 11 To 47 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) Next intCounter End Sub From now on I will just show the loop body for clarity. As always, we recall that the rest of the code is really there

For intCounter = 1 To 10 Step 2 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) Next intCounter We can use the Step option to count in increments other that 1 Lets show all the odd numbers from 1 to …

For intCounter = 10 To 1 Step -1 bntRedDemo.Text = (intCounter).ToString bntRedDemo.Refresh() Sleep(1000) Next intCounter bntRedDemo.Text = "We have liftoff!" We can use the Step option to count in increments other that 1 We can use a negative step to count backwards …

Dim strS As String strS = “” For intCounter = 1 To 5 strS = strS & (intCounter).ToString bntRedDemo.Text = strS Next intCounter But how do we do this?

Case Study I Lets us add up all the integers from 1 to …

Dim intTotalCount As Integer intTotalCount = 0 For intCounter = 1 To 100 intTotalCount = intTotalCount + intCounter Next intCounter bntRedDemo.Text = intTotalCount.ToString

Case Study II Lets us multiply up all the integers from 1 to 10 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 Also called 10 factorial, denoted as 10!

Dim intTotal As Integer intTotal = 1 For intCounter = 1 To 10 intTotal = intTotal * intCounter Next intCounter bntRedDemo.Text = intTotal.ToString

Case Study III Lets us multiply up all the integers from 1 to * 2 * 3 * 4 * 5 …* 98 * 99 * 100 Stop: We can not do this. 100! Is much larger than 2,147,483,647, in fact 100! Is much larger than our long type (9,223,372,036,854,775,807)

Case Study II Lets us add up all the integers from Low to High, where Low and High are not known in advance Low + (Low +1) + (Low +2)… + High

Dim intTotalCount, intLow, intHigh As Integer intTotalCount = 0 intLow = ‘ assume some code that gets the value intHigh = ‘ assume some code that gets the value For intCounter = intLow To intHigh intTotalCount = intTotalCount + intCounter Next intCounter bntRedDemo.Text = intTotalCount.ToString