0% found this document useful (0 votes)
6 views20 pages

Repetition

The document discusses repetition structures in programming, specifically in Visual Basic, detailing types such as Do While, For, and Do/Loop Until structures. It explains how these loops control the execution of code based on specified conditions, providing examples and simulations for clarity. Additionally, it includes performance tasks and assignments to reinforce understanding of the concepts presented.

Uploaded by

Ruthchie Staana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

Repetition

The document discusses repetition structures in programming, specifically in Visual Basic, detailing types such as Do While, For, and Do/Loop Until structures. It explains how these loops control the execution of code based on specified conditions, providing examples and simulations for clarity. Additionally, it includes performance tasks and assignments to reinforce understanding of the concepts presented.

Uploaded by

Ruthchie Staana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Repetition

JEFFREY A. ALARCON
ICT 202
OBJECTIVES
• Discuss and enumerate the different repetition
structures.
• Recognize the differences of the structure of
Repetition statement.
A short review: (Case Block
statement)
Repetition
In this lesson, we shall examine another way to control the program
flow, that is, the repetition structure. A repetition statement that both
defines the boundaries containing the repeating section of code and
controls whether the code will be executed or not
Repetition:
LOGIC OF REPETITION:

Repetition: allows the user to do the same action of program


until the given condition is true.
Types of Repetition Structure
There are three different forms of Visual Basic repetition structures.
1. Do While structures,
2. For structures, and
3. Do/Loop Until structures.
Do loops
A loop is a statement used in most programming languages to repeat a
sequence of procedure as specified on the number of times it should
repeat a certain action.
This loop statement repeats a sequence of statements or procedures as
long as the condition is true.
1. Do while
2. Do until
Do while……Loop statement
The do while….loop is used to execute statements until a specified
condition is met.
Syntax:
Do while <condition>
statement/s
Loop
Note: As seen on the structure, if first checks the condition set to this and
if the condition is true the proceeding statements are executed. On the
other hand if the condition is not met then the sequence of procedures is
not executed.
Example
1. Once the command button is clicked numbers 1 to 10 will be
printed in the form.
SIMULATION
Num=1 num<=10 T/F Print num num=num+1
1 1<=10 T 1 2=1+1
2 2<=10 T 2 3=2+1
3 3<=10 T 3 4=3+1
4 4<=10 T 4 5=4+1
5 5<=10 T 5 6=5+1
6 6<=10 T 6 7=6+1
7 7<=10 T 7 8=7+1
8 8<=10 T 8 9=8+1
9 9<=10 T 9 10 = 9 + 1
10 10<=10 T 10 11 = 10 + 1 (STOP)
Example 2
1. Write a program to find sum and print the numbers that are less
than 10 on the form of Visual Basic program, the program stopped
and end at number 5 ?
Simulate example 2:
Answer:
Performance Task 1
Once the command button is clicked numbers 1 to 10 will be printed
inside a form. This program is known as the FIBONACCI SEQUENCE
wherein the first 10 consecutive numbers (0,1,2,3,4,5,6,7,8 and 9) are
added and displays the results.
Do Until….Loop statement
Note: The do while….loop statement looks for the TRUE value of the
set condition.

Do until….loop statement look for FALSE value out of the condition.


This means that the procedure under this loop statement is executed as
long as the loop test evaluates a FALSE value.
Do until…loop statement
Syntax:
Do until<condition>
Statement(s)
loop
Example

Using this condition gives a false value, since the program will just print numbers that are less than and equal to 10
Example 2
Performance task 2
Use any of the repetition statements in this program, which will allows
the user to enter three incorrect, passwords before is disabled. If the
password is equal to “COMPUTER”, then label displays “ACCESS
GRANTED”, else , it will display “TRY AGAIN”. However, if the user has
entered three incorrect passwords, the form will be disabled.
Assignments:
1. Define For…loop statement
2. Syntax
3. Give one sample program of for…loop statement
4. Quiz

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy