1 / 10

looping

looping. LOOPING. Used to perform repetitive tasks Tasks use the same set of statements that are executed again and again until a specific condition is met Statements will loop until the condition is false. Do…loop. A looping structure that evaluates the loop at least one time

luke
Download Presentation

looping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. looping

  2. LOOPING • Used to perform repetitive tasks • Tasks use the same set of statements that are executed again and again until a specific condition is met • Statements will loop until the condition is false

  3. Do…loop • A looping structure that evaluates the loop at least one time • Dim intNum as Integer • Do • intNum = intNum + 2 • Loop While intNum < 10

  4. Do while … loop • A looping structure that may or may not evaluate the loop. • The condition is FIRST • Dim intNum as Integer • Do While intNum < 10 • intNum = intNum + 2 • Loop

  5. Infinite loops • Continues forever because the condition is never false • Happens when there is a logic error – will eventually cause a run time error • Dim intNum as Integer = 1 • Do While intNum > 0 • intNum = intNum + 1 • Loop

  6. Input boxes • The Inputbox() function displays an input box with a prompt and a text box • The information entered by the user is the new value for a string variable • Dim strName as String • strName = InputBox(“Enter your name”, “Name”) • “Enter your name” is the prompt • “Name” is the title of the InputBox

  7. Accumulator variables • Counters used within loops to update a numeric variable are called accumulator variables • intTotalScore = intTotalScore + intNewScore • Each time this statement is executed, the value of intNewScore is added to the current value of intTotalScore and then this new value is assigned to intTotalScore

  8. flags • A flag, also called a sentinel, is a condition used to signify that a loop should stop executing • It’s an easy way to end a loop

  9. For…next statement • Executes a set of statements a fixed number of times – not Boolean • Forcounter = startToend • statements • Next counter • Counter is initialized to the start number when the loop first executes and is automatically incremented by 1

  10. For…next statement • Dim intNumber as Integer • ForintNumber = 1 To 10 • Messagebox.Show(intNumber) • Next intNumber

More Related