Computer Programming Looping Structures - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Computer Programming Looping Structures

Description:

Nested statements should be indented for good programming style. 11/11/09 ... It is used to get information from the user. SYNTAX. InputBox(prompt, title) ... – PowerPoint PPT presentation

Number of Views:242
Avg rating:3.0/5.0
Slides: 14
Provided by: ITS8231
Category:

less

Transcript and Presenter's Notes

Title: Computer Programming Looping Structures


1
Computer ProgrammingLooping Structures
  • Mr. Blochowski
  • http//www.sfstoledo.org/classes/vbasic/csvb.htm

2
Looping Structure
When a program repeats a group of statements a
number of times, the repetition is accomplished
using a loop.
The code required to create a loop is sometimes
called an iteration structure.
3
Types of Looping Structures
2 Types of Looping Structures A. Definite
loop repeats a set number of times. B.
Indefinite loop repeats an unknown number of
times.
4
Indefinite Loops
  • Do. . .While is a looping structure that
    executes a set of statements as long as a
    condition is TRUE.
  • 2. Do. . .Until is a looping structure that
    repeats a block of code until a condition becomes
    TRUE.

5
SYNTAX
Do While (boolean expression) statements Loop
Example intValue 1 Do While (intValue lt
10) intValue intValue 1 Loop
6
SYNTAX
Do statements Loop Until (Boolean Expression)
Example intValue 1 Do intValue intValue
1 Loop Until (intValue gt 10)
7
Infinite Loops
In an infinite loop, the condition that is
supposed to stop the loop from repeating never
becomes True. A logic error could lead to an
infinite loop.
Example intValue 1 Do While (intValue lt
10) intValue intValue 1 Loop
8
Nested Loops
Nested Loop statements contain a looping
structure inside another looping
structure. Example intValue 1 Do While
(intValue lt 100) intSum 1 Do intSum
intSum 1 Loop Until (intSum gt 5) intValue
intValue intSum Loop
Note Nested statements should be indented for
good programming style.
9
Definite Looping Structure
The ForNext statement is a looping structure
that executes a set of statements a fixed number
of times.
Syntax For counter start To end statements Next
counter
Counter, start, and end are integer variables,
values, or expressions. Counter is initialized
to start(counter start)only once when the loop
first executes, and compared to end before each
loop iteration. Counter is automatically
incremented by 1 after each iteration of the loop
body (statements).
10
For..Next Statement
Example Dim intCounter As Integer For intCounter
1 To 10 Print intCounter Next intCounter
11
Nested For Loops
For intOuter 1 To 10 For intInner1 1 To
2 Code goes here Next intInner1 For
intInner2 1 To 4 Code goes here Next
intInner2 Next intOuter
The indentation of the code helps you to identify
which Next statement is paired with each For
statement.
12
Input box
An input box is a Visual Basic predefined dialog
box that has a prompt, a text box, and OK and
Cancel buttons. It is used to get information
from the user.
SYNTAX InputBox(prompt, title)
Prompt is a String variable or a string enclosed
in quotation marks. Title is an optional String
variable or a string enclosed in quotation marks.
When the OK button is selected, the data in the
text box is returned by the InputBox function.
13
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com