Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 04 (Part III) Control Statements: Part I.
CS0004: Introduction to Programming Repetition – Do Loops.
1 Loops zDo While Loop: yRepeats a block of code WHILE a condition remains TRUE Do While condition Code to execute Loop.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
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
CHAPTER SIX Loop Structures.
CHAPTER 6 Loop Structures.
© 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.
Variables and Constants
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.
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.
Chapter 12: How Long Can This Go On?
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
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.
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.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
© 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.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
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.
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.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
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.
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
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. 
A variable is a name for a value stored in memory.
UNIT 5 Lesson 15 Looping.
Controlling Program Flow with Looping Structures
REPETITION CONTROL STRUCTURE
3rd prep. – 2nd Term MOE Book Questions.
3rd prep. – 2nd Term MOE Book Questions.
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Chapter 6 The while Statement
Chapter 5 The Do…Loop Statement
Chapter 8 JavaScript: Control Statements, Part 2
Chapter (3) - Looping Questions.
T. Jumana Abu Shmais – AOU - Riyadh
CIS 16 Application Development Programming with Visual Basic
Additional Topics in VB.NET
Presentation transcript:

Chapter 6 Looping Structures

Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates the statement at least once Do While intx < 10 intx=intx + 1 Loop

Infinite Loops May have problems with loops –Logic error –Overflow error –Infinite Loop

Input Box Pop-up text box that allows the user to input information Has a prompt, text box, OK and cancel button How to display: strx = InputBox(“prompt”, “title”) intx = val(strx) me.lbl.text = intx If text box is blank = nothing

Accumulator Variables Variable that stores an accumulating score Keeps a running total or sum Just like a counter intTotal = intTotal + intScore Keep in mind if you’re adding decimals or integers

Flags or Sentinels Something significant in your program that stops program execution or ends a loop Generally declared as a constant Inputbox(“Enter a positive number (-1 to finish)”)

For…Next Statement Looping structure that performs a set number of times Operates until a counter reaches an ending value

String Class The string data type is a class containing multiple properties String class properties:

String Class Example: Think of a String as a row of numbered boxes. The first boxe’s number is zero and they go up from left to right. Only one letter can be in each box SUMMER

String Methods Methods are procedures within a class.ToUpper.ToLower.Trim.TrimEnd.TrimStart.PadLeft(length,”char”).PadRight(length, “char”)

String Substring These return a portion of the string.Substring(startPos, numOfChars).Remove(startPos, numOfChars).Replace(oldString, newString).Insert(startPos, substring).IndexOf(substring)

String Class Examples Dim strSeason As String = “SummerTime” Dim strNewString As String strNewString = strSeason.ToUpper ‘SUMMERTIME strNewString = strSeason.ToLower ‘summertime strSeason = “ SummerTime “ strNewString = strSeason.Trim ‘SummerTime strNewString = strSeason.TrimEnd ‘ SummerTime strNewString = strSeason.TrimStart ‘SummerTime

Examples Cont… strSeason = “SummerTime” strNewString = strSeason.PadLeft(15, ”x”) ‘xxxxxSummerTime strNewString = strSeason.PadLeft(9, “x”) ‘SummerTime strNewString = strSeason.PadRight(13, “x”) ‘SummerTimexxx

Examples Cont… Dim strSeason As String = “SummerTime” Dim strNewString As String Dim intPos As Integer strNewString = strSeason.Substring(6,4) ‘Time strNewString = strSeason.Remove(0,6) ‘Time strNewString = strSeason.Replace(“Time”, “ is fun!”) ‘Summer is Fun strNewString = strSeason.Insert(6, “ is a fun “) ‘Summer is a fun Time intPos = strSeason.IndexOf(“mer”)‘3

String Concatenation Join two or more strings together String.concat(string1, string2) The & operator also joins strings To add spaces use empty quotes or Space(#) The Space function will add a stated number of spaces vbTab adds 8 spaces, vbCrLf - returns

Char Structure A structure is a simple form of a class Like the class, a structure has properties chr1 = char.ToUpper(chr2) chr3 = char.ToLower(chr2)

Comparing Strings Used to alphabetize a list Compare(string1,string2,Case-insensitive) –Case-insensitive should be true or false True-case is not considered, a, A 0-string1 and string 2 equal 1-string1 is after string2 -1-string1 is before string2

Like Operator The Like is used as a Boolean expression –String1 Like String2 –True if String1 matches the pattern of String2 –False if there is no match –? Used for a single character –* used for many characters –# used for a single number –[] used to enclose a list of characters – used to indicate a range of characters in a character list –, used to separate characters in a character list