MELJUN CORTES Looping Structure
-
Upload
meljun-cortes-mbampa -
Category
Documents
-
view
215 -
download
0
Transcript of MELJUN CORTES Looping Structure
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 1/40
Looping Structure
Rommel Dorin
MELJUN CORTES
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 2/40
Testing Data
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 3/40
Keypress
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 4/40
Explained
KeyChar property to determinethe pressed key. (KeyChar
stands for "key character.") You
then use the e parameter's
Handled property to cancel the
pressed key if it is aninappropriate one. Example
shows using the KeyChar and
Handled properties in the
KeyPress event procedure.
Notice that you refer to the
Backspace key on a computer keyboard using the
ControlChars.Back constant.
The Backspace key is necessary
for editing the text box entry.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 5/40
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 6/40
Looping
• The condition is evaluated with each
repetition (or iteration) of the loop and can
be phrased in one of two ways: It can
specify either the requirement for repeating the instructions or the
requirement for not repeating them .
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 7/40
Looping
• The requirement for repeating the
instructions is referred to as the looping
condition, because it indicates when the
computer should continue “looping” through the instructions.
• The requirement for not repeating the
instructions is referred to as the loop exitcondition, because it tells the computer
when to exit (or stop) the loop.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 8/40
Looping
• A repetition structure can be either a pretest
loop or a posttest loop.
• In a pretest loop, the loop condition is
evaluated before the instructions within theloop are processed.
• In a posttest loop, the evaluation occurs after
the instructions within the loop areprocessed. Depending on the result of the
evaluation, the instructions in a pretest loop
may never be processed.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 9/40
Do…Loop
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 10/40
Do…Loop
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 11/40
Do…Loop
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 12/40
Do…Loop
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 13/40
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 14/40
For Next Loop
•For . . . Next loops are usually usedwhen you know the number of
times you want to repeat a loop.
The top of the loop is marked witha For statement and Next marksthe end of the loop. For loops use
a counter to keep track of times itruns.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 15/40
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 16/40
For Next Loop
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 17/40
Counting Loops
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 18/40
For…Next Loop
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 19/40
For…Next Loop Flowchart
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 20/40
Step Parameter
• The Step parameter determineshow fast you move through a
loop.
• For loops can use positive and
negative numbers, and they can
also change by decimal values.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 21/40
Loop Control Variables
•The numeric variable that
controls a For . . . Next loop
increments until it’s larger than its limit. (If it steps
backward, it decrementsuntil it’s smaller than its limit.)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 22/40
Do While Loops
• For . . . Next loop is controlled by a
numeric variable
• While loop can be controlled with astring, a Boolean, or a numeric
variable.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 23/40
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 24/40
Do While Loops
Syntax:
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 25/40
Counting Loops
• A While loop can mimic a For . . . Nextloop. It can be initialized to any value,
increment or decrement as needed,
and end when a specified value is
reached.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 26/40
Counting Loops
i = 1
Do While i<= 5
rtbOut.AppendText(i.ToString & vbNewLine)
i = i+1
Loop
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 27/40
Do Loop While
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 28/40
Sentinel Values
• Sentinel values are set with each tripthrough the loop.
• As soon as that value makes the
condition False, the loop ends.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 29/40
Do While – Example 1
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 30/40
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 31/40
Do Until Loops
Syntax:
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 32/40
Do Loop While
There’s a variation on the While loop.Instead of putting the condition in the Do
line, the While condition is placed in the
Loop line.
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 33/40
Exit Statement
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 34/40
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 35/40
Example
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 36/40
Activity
• Depreciation Program
• Formula:
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 37/40
Activity
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 38/40
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 39/40
Rnd
• Rnd is short for random. It’s used to generate a
random number. Random numbers are great.
• Rnd generates a random number greater or
equal to 0 and less than 1. The range is 0 to.999999.
• Syntax:
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 40/40
ID Random Generator