© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition.

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.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6: Repetition  Some additional operators increment and decrement.
5.05 Apply Looping Structures
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
Chapter 5 new The Do…Loop Statement
© 2007 Lawrenceville Press Slide 1 Chapter 6 The while Statement  Loop structure that executes a set of statements as long as a condition is true  The.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in String Functions (3%)
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
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 12: How Long Can This Go On?
1 © 2000 John Urrutia. All rights reserved. Qbasic Looping Statements & Formatted Output.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Introduction to Programming with RAPTOR
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Repetition Statements
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Controlling Program Flow with Looping Structures
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Controlling Program Flow with Decision Structures.
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()
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
Looping Structures. A B dialog box that pops up and prompts the user for input Text area that pops up and prompts the user for to wait while it gets.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 Controlling Program Flow with Looping Structures.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
Microsoft Visual Basic 2008: Reloaded Third Edition
A variable is a name for a value stored in memory.
Controlling Program Flow with Looping Structures
Introduction to Scripting
3rd prep. – 2nd Term MOE Book Questions.
Repeating Program Instructions
Chapter 6 The while Statement
Arrays, For loop While loop Do while loop
Making Decisions in a Program
Chapter 5 The Do…Loop Statement
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter (3) - Looping Questions.
CIS 16 Application Development Programming with Visual Basic
Fundamentals of visual basic
Microsoft Visual Basic 2005: Reloaded Second Edition
Introduction to Computer Science
Presentation transcript:

© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true.  The condition is a Boolean expression.  Executes at least once.  The terminating condition is checked after the body of the loop is executed.  The loop below iterates while sum is less than 10: sum = 0; Do sum += 2 Loop While sum < 10

© 2006 Lawrenceville Press Slide 2 Chapter 6 Pre-Test Do…Loop  Executes only if the condition is initially true. May not iterate at all.  The terminating condition is checked before the body of the loop is executed.  The statement sum = 20 Do While sum < 10 sum += 2 Loop does not iterate at all because sum is initially greater than 10.

© 2006 Lawrenceville Press Slide 3 Chapter 6 Infinite Loops  A loop that continues executing forever  Can be caused by syntax or logic errors. For example: num = -1 Do num -= 1'num is decreased by 1 While num < 0  Some errors result in an overflow causing a run-time error.

© 2006 Lawrenceville Press Slide 4 Chapter 6 The InputBox Function  Displays a predefined dialog box that has a prompt, a text box, and OK and Cancel buttons, and then returns a string.  Used to obtain information from the user.  The function is used as part of an assignment statement: stringVar = InputBox(prompt, title)  Clicking Cancel or leaving the text box blank returns Nothing.  The Val() function can be used to convert string data to numeric data.

© 2006 Lawrenceville Press Slide 5 Chapter 6 Accumulator Variables  A variable that is incremented by a varying amount.  accumulator = accumulator + value  Often used for keeping a running total.  intTotalScore = intTotalScore + intNewScore  intTotalScore += intNewScore  Should be initialized when declared.

© 2006 Lawrenceville Press Slide 6 Chapter 6 Assignment Operators OperatorOperation += addition and then assignment -= subtraction and then assignment *= multiplication and then assignment /= division and then assignment \= integer division and then assignment ^= exponentiation and then assignment

© 2006 Lawrenceville Press Slide 7 Chapter 6 Using Flags  A flag, or sentinel, indicates when a loop should stop iterating.  Often a constant.  Code is easier to modify when sentinels are constants declared at the beginning of a procedure.

© 2006 Lawrenceville Press Slide 8 Chapter 6 The For…Next Statement  Loop structure that executes a set of statements a fixed number of times.  Uses a counter to control loop iterations.  The keyword Step can optionally be used to change the amount the counter is incremented or decremented.  The loop below executes until num is equal to 10: For num As Integer = 0 To 10 i += num Next num

© 2006 Lawrenceville Press Slide 9 Chapter 6 The String Class  Includes properties and methods.  A String object is comprised of a sequence of characters with the first character at index position 0.  String properties include: Chars(index) Length()

© 2006 Lawrenceville Press Slide 10 Chapter 6 String Methods  String methods for manipulating a string include: ToUpper converts a string to all uppercase ToLower converts a string to all lowercase Trim removes spaces from the beginning and end of a string TrimEnd removes spaces from the end of a string TrimStart removes spaces from the beginning of a string PadLeft(len, char) adds a specified character to the beginning of a string until the string is len characters long PadRight(len, char) adds a specified character to the end of a string until the string is len characters long

© 2006 Lawrenceville Press Slide 11 Chapter 6 String Methods (cont.)  String methods for manipulating a substring: Substring(startPos, numOfChars) returns the substring that is numOfChars in length and starts at startPos Remove(startPos, numOfChars) deletes the substring that is numOfChars in length and starts at startPos Replace(oldString, newString) exchanges every occurrence of oldString with newString Insert(startPos, substring) inserts substring at startPos IndexOf(substring) returns the first position of substring

© 2006 Lawrenceville Press Slide 12 Chapter 6 String Concatenation  Concatenation is joining two or more strings together.  The String method Concat() joins two or more strings. It is a shared method and must be used with the String class, not an object of the class: s = String.Concat("this","and","that")  The &= operator concatenates a string to an existing string: s = "thisand" s &= "that"  The & operator concatenates strings: s = "this" & "and" & "that"

© 2006 Lawrenceville Press Slide 13 Chapter 6 String Concatenation (cont.) Dim strSeason As String = "SummerTime" Dim strMessage As String = " is a fun time!" Dim strNewString As String 'SummerTime is a fun time! strNewString = String.Concat(strSeason, strMessage) Dim strFirstName As String, strLastName As String Dim strFullName As String strFirstName = "Elaine" strLastName = "Malfas“ 'Elaine Malfas strFullName = strFirstName & " " & strLastName

© 2006 Lawrenceville Press Slide 14 Chapter 6 Space(), vbTab, vbCrLf  The Space() function returns a string of spaces.  vbTab is a built-in constant that represents 8 spaces.  vbCrLf is a built-in constant that represents a carriage return-linefeed combination.

© 2006 Lawrenceville Press Slide 15 Chapter 6 The Char Structure  A simple form of a class.  Char has two shared methods: ToUpper() ToLower() The methods must be used with the Char structure: newLetter = Char.ToUpper(letter1)

© 2006 Lawrenceville Press Slide 16 Chapter 6 Unicode  A digital code with representations for every character in every language and symbol.  Table with some examples : pg  Two built-in functions for converting between characters and Unicode: AscW(char) ChrW(integer)

© 2006 Lawrenceville Press Slide 17 Chapter 6 Comparing Strings  When relational operators (=, >, =, ) are used to compare strings, their Unicode values determine the relationship between the strings.  The Compare() method is a better choice to alphabetically compare strings: Compare(string1, string2, case-insensitive) returns 0 if string1 and string2 are the same. A positive number is returned if string1 is greater than string2 and a negative number if string1 is less than string2. case-insensitive should be true if the case of the strings should not be considered.

© 2006 Lawrenceville Press Slide 18 Chapter 6 The Like Operator  Used to perform a textual comparison between two strings.  Can be used to perform pattern matching. The pattern can include: ?used in place of any single character *used in place of many characters #used in place of any single number []used to enclose a list of characters -used to indicate a range of characters in a list,used to separate characters in a list