CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.

Slides:



Advertisements
Similar presentations
Chapter 6 - VB 2005 by Schneider1 Do Loop Syntax Do While condition statement(s) Loop Condition is tested, If it is True, the loop is run. If it is False,
Advertisements

The "if structure" is used to execute statement(s) only if the given condition is satisfied.
CS0004: Introduction to Programming Repetition – Do Loops.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Visual Basic.NET BASICS Lesson 10 Do Loops. 2 Objectives Explain what a loop is. Use the Do While and Do Until loops. Use the InputBox function. Use the.
1 Loops zDo While Loop: yRepeats a block of code WHILE a condition remains TRUE Do While condition Code to execute Loop.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
REPETITION (loops or iteration) Schneider: Sec. 6.1 & 6.3.
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 Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Control Structures: Part 1. Introduction Control Structures If / Then Selection Structure If / Then / Else Selection Structure While Repetition Structure.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
CP Week 7 Looping constructs Aims and Objectives zUnderstand what the while group of loops are and why they are needed zBe able to design and code.
5.05 Apply Looping Structures
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
110-K1 Iterations (1) Up to now, need to call the procedure again (e.g. click again on a command button) To repeat a piece of code: Can also use loops:
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
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 12: How Long Can This Go On?
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate 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.
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 1B) UTPA – Fall 2011.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
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.
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 SIX LOOPS © Prepared By: Razif Razali 1. FORMAT OR REFRESH!! WHAT HAVE WE LEARN? Differentiate between the types of selection structure? Which.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
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.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Repetition Statements
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
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.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Chapter 13 Do It, Then Ask Permission (Posttest Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Controlling Program Flow with Looping Structures
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Loop Blocks Chapter 6 Part A. Program Blocks 1.Actions- commands, messages, methods 2.Branches- decisions to be made 3.Loops- actions to be repeated.
1 VB-04-Control Structures 16 March 2016 Visual Basic Control Structures - Selection.
Chapter 6 Controlling Program Flow with Looping Structures.
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.
Problem Solving and Control Statements: Part 2
While Loops Chapter 3.
3rd prep. – 2nd Term MOE Book Questions.
Introducing Do While & Do Until Loops & Repetition Statements
Control Structures: Part 1
حلقات التكرار.
Chapter (3) - Looping Questions.
CMPT 102 Introduction to Scientific Computer Programming
Three Special Structures – Case, Do While, and Do Until
Fundamentals of visual basic
Case & Repetitive Statements
A LESSON IN LOOPING What is a loop?
Prepared By: Deborah Becker
Presentation transcript:

CSC 162 Visual Basic I Programming

Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit condition is tested after the body is executed at least once

Pretest Loops While/Wend or Do While/Loop Do Until/Loop

While/Wend or Do While/Loop While condition body_of_code Wend Do While condition body_of_code Loop As long as the condition remains satisfied, the loop will continue to execute. Once the condition is false, the code will resume execution after the Wend or Loop statement.

Example Dim intCounter As Integer Dim intSquare As Integer intCounter = 0 Do While intCounter <= 10 intSquare = intCounter ^ 2 Print intCounter & " squared is " & intSquare intCounter = intCounter + 1 Loop

Do Until/Loop Do Until condition body_of_code Loop As long as the condition is not satisfied, the loop will continue to execute. Once the condition is true, the code will resume execution after the Loop statement.

Example Dim intCounter As Integer Dim intSquare As Integer intCounter = 0 Do Until intCounter > 10 intSquare = intCounter ^ 2 Print intCounter & " squared is " & intSquare intCounter = intCounter + 1 Loop

MsgBox Function intUserChoice = MsgBox("Your average is " & sngAverage, _ vbOkOnly, "Average") MsgBox(Message, Type, Title) The message box is used to display information or to provide the user with a choice. The message box will provide information back to the program about which button the user presses, so it needs to be assigned to an integer variable. Types of message boxes are found in Section (pages 438 – 443).

Class Discussion Page 125 #4.11 Lab Page 125 #4.16