MELJUN CORTES Looping Structure
-
Upload
meljun-cortes-mbampa -
Category
Documents
-
view
222 -
download
0
Transcript of MELJUN CORTES Looping Structure
![Page 1: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/1.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 1/40
Looping Structure
Rommel Dorin
MELJUN CORTES
![Page 2: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/2.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 2/40
Testing Data
![Page 3: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/3.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 3/40
Keypress
![Page 4: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/4.jpg)
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.
![Page 5: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/5.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 5/40
![Page 6: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/6.jpg)
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 .
![Page 7: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/7.jpg)
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.
![Page 8: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/8.jpg)
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.
![Page 9: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/9.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 9/40
Do…Loop
![Page 10: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/10.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 10/40
Do…Loop
![Page 11: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/11.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 11/40
Do…Loop
![Page 12: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/12.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 12/40
Do…Loop
![Page 13: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/13.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 13/40
![Page 14: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/14.jpg)
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.
![Page 15: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/15.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 15/40
![Page 16: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/16.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 16/40
For Next Loop
![Page 17: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/17.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 17/40
Counting Loops
![Page 18: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/18.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 18/40
For…Next Loop
![Page 19: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/19.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 19/40
For…Next Loop Flowchart
![Page 20: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/20.jpg)
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.
![Page 21: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/21.jpg)
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.)
![Page 22: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/22.jpg)
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.
![Page 23: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/23.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 23/40
![Page 24: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/24.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 24/40
Do While Loops
Syntax:
![Page 25: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/25.jpg)
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.
![Page 26: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/26.jpg)
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
![Page 27: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/27.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 27/40
Do Loop While
![Page 28: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/28.jpg)
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.
![Page 29: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/29.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 29/40
Do While – Example 1
![Page 30: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/30.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 30/40
![Page 31: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/31.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 31/40
Do Until Loops
Syntax:
![Page 32: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/32.jpg)
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.
![Page 33: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/33.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 33/40
Exit Statement
![Page 34: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/34.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 34/40
![Page 35: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/35.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 35/40
Example
![Page 36: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/36.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 36/40
Activity
• Depreciation Program
• Formula:
![Page 37: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/37.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 37/40
Activity
![Page 38: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/38.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 38/40
![Page 39: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/39.jpg)
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:
![Page 40: MELJUN CORTES Looping Structure](https://reader031.fdocuments.net/reader031/viewer/2022021220/577cd7ff1a28ab9e78a02ff0/html5/thumbnails/40.jpg)
7/27/2019 MELJUN CORTES Looping Structure
http://slidepdf.com/reader/full/meljun-cortes-looping-structure 40/40
ID Random Generator