1 / 8

Tutorial 6 The Repetition Structure

Tutorial 6 The Repetition Structure. The Repetition Structure (Looping) Lesson A Objectives. After completing this lesson, you will be able to: Code the repetition structure using the For…Next and Do…Loop statements Write pseudocode for the repetition structure

Download Presentation

Tutorial 6 The Repetition Structure

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. Tutorial 6The Repetition Structure

  2. The Repetition Structure (Looping)Lesson A Objectives After completing this lesson, you will be able to: • Code the repetition structure using the For…Next and Do…Loop statements • Write pseudocode for the repetition structure • Create a flowchart for the repetition structure • Display a message in the Output window while an application is running • Change the location and size of a control while an application is running • Initialize and update counters and accumulators

  3. The Repetition Structure - Loops • Programmers use the repetition structure, referred to more simply as a loop, when they need the computer to repeatedly process one or more program instructions. • In a pretest loop, the evaluation occurs before the instructions within the loop are processed • In a posttest loop, the evaluation occurs after the instructions within the loop are processed

  4. The For … Next Loop • You can use the For…Next statement for processing a precise number of times • Syntax: For counter = startValue To endValue [Step stepValue] [instructions you want repeated] Next • counter is the name of a numeric variable and it keeps track of how many times the loop instructions are repeated • startValue, endValue, and stepValue must be numeric and they can be either positive or negative, integer or non-integer (default stepValue is 1)

  5. For … Next Examples

  6. The Do…Loop Statement • Unlike the For…Next statement, the Do…Loop statement can be used • for processing a conditional number of times – pretest or posttest • The Do…Loop statement begins with the Do clause and ends with the • Loop clause

  7. Do … Loop Examples

  8. Counters and accumulators are used within a repetition structure to calculate subtotals, totals, and averages Initializing (usually to 0 or 1) means to assign a beginning value to the counter or accumulator before the loop A counter is a numeric variable used for counting something and is typically updated by 1 An accumulator is a numeric variable used for accumulating (adding together) and is updated by an amount that varies Using Counters and Accumulators

More Related