Professional Documents
Culture Documents
see in the
pictures?
ROLLER
COASTER
met.
ITERATIVE, ITERATION, AND LOOP
◦Iteration – refers to the
process of repeating statement/s
in a program. One (1) form of
iteration is a loop. If the
sequence of statements is
executed repeatedly, it is called a
loop. This Photo by Unknown Author is
licensed under CC BY-SA-NC
ITERATIVE FLOWCHART
◦Iterations can be best
illustrated using
flowcharts.
In Iterative flowcharting, a
statement or sequence of
statements is executed
repeatedly as long as a
condition holds True.
EXAMPLE 1: Name
◦ Create a flowchart that asks the user to input a name. The program will
display the name five (5) times.
◦ Pseudocode
1.Initialize counter = 0
2. Input name
3. Display name
4.Increment the value of counter by 1
5. If counter = 5 then
Program ends
Else
Repeat steps 3 to 5
EXAMPLE 1: Name
◦ Create a flowchart that
asks the user to input a
name. The program will
display the name five (5)
times.
◦ FLOWCHART
EXAMPLE 3: Sum of Three Numbers
◦ Create a flowchart that displays the sum of the three(3) numbers
entered by the user.
◦ Pseudocode
1. Initialize counter=0
2. Initialize sum=0
3. Input a number
4. Add the entered number to the value of sum.
5. Increment the value of counter by 1.
6. If counter=3 then
Display sum
Program ends
Else
Repeat steps 3 to 6
FOR NEXT LOOP
◦Hands-on Practice (Counter) (Syntax 1)
1. Create one button on a form, with text caption Counter
2. Double- click the button and type the following:
Dim intNum as Integer
Dim intNum2 as Integer
For intNum =1 to 10 step 1
◦ intNum2=intNum2 +1
◦Msgbox (“value of j is:” & intNum2)
Next intNum
End Sub
FOR NEXT LOOP
❑Syntax 1:
◦ For variable_counter= startNumber to endNumber
◦VB statement/s
◦ Next
❑Syntax 2:
• For variable_counter= startNumber to endNumber step
increment/decrement
◦VB statement/s
◦ Next
FOR NEXT LOOP
1.Hands-on Practice (Counter) (Syntax 2)
1. Create one button on a form, with text caption Counter
2. Using For Next (syntax no. 2), create a program that will
display only the odd numbers from 1-20.
2.Using For Next (syntax no. 2), create a program that
◦will display only the even numbers from 1-20
USING LOOP WITH
CONDITIONAL
STATEMENT(COUNTER
AND ACCUMULATOR)
DAY 2
FOR NEXT LOOP WITH COUNTER
AND ACCUMULATOR
❑Counter is a numeric variable used for counting something such
as the number of employees paid in a week.
• References:
Simple Program Logic Formulation by Jerald Herrera De La Rosa
• Visual Basic.NET by Diane Zak