3Q 10 Week 4-5

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

COMPUTER 10

NAME: ______________________________________________________ DATE: ______________


WEEK 4-5
Topic: LOOP STRUCTURES

Objectives:
At the end of the day, I will be able to:
a. understand how For-Next statements work;
b. state the function of Do-Loop statements;
c. use While-Wend statements to replace Do-Loop statements; and
d. identify the loop structures to be used when making programs

Fuel – Up:
Discussion:
LOOP STRUCTURES
Loop structures repeat a block of statements. These statements are executed for an
indefinite number of times while a condition is true, or until a condition becomes true.

FOR - NEXT STATEMENTS


For next statements are used to repeat statement s or a series of statements while
the value of the counter is within the start-to-end value.
The value of the counter increases by 1 automatically; however, it can be set to
increase by a specified number using the Step statement.

DO LOOP STRUCTURE
Do loop structure are statements that are executed while the condition in a Do-Loop
statement is true.

DO-UNTIL STATEMENTS
-are statements that are executed while the condition in a Do-Loop statement is
False.

WHILE-WEND STATEMENTS
-similar in structure to the Do-Loop statement.
While-Wend statement can be replace the Do While Loop in a Do-Loop statement.
One disadvantage, however, is that the While-Wend statement does not have a way
to exit prematurely. The For-Next loop has the Exit command for that purpose, while
the Do-Loop has the Exit Do.

NESTED LOOP STATEMENTS


There will be times when you need to put a loop within a loop. An example of this is
when you need to create an array or a table. When creating a loop within a loop,
always make sure that the variable of the outer loop is different from the variables of
the inner loops.
THE LOOP STRUCTURES
Repetition structures, known as loops, offer a flexible yet convenient way to
repeatedly process instructions in a program. Loops have many applications in
computer programming.

Keywords. Loops are also used in computer graphics programming, such as


animation. Many frames are displayed within a loop showing an animation. Loops are
also used when programming microprocessors and computing numerical series.
There are three basic programming structures that are used in high-level
programming languages. These structures are sequential selection, and repetition.
The sequential structure is a segment of code where the statements get executed in
a sequence from top to bottom. The selection structure involves an If or a
Select/Case statement, where the program execution branches to a new line, based
on the outcome of a decision. The repetition structure, often referred to as a Loop, is
used when a segment of code needs to be executed repeatedly. Usually, a condition
controls the continuation of a loop. There are different repetition structures available
in Visual Basic VB.NET.

There are certain terms that are used when working with loops. Here are some of the
common terms that you should familiarize yourself with before reading any further:
Body of the loop: Body of the loop is the segment of code that gets executed
repeatedly.
Iteration/Cycle: Each time the statements in the loop body get executed is
referred to as one iteration or cycle. > Loop Condition: There is usually a
condition that controls the continuation or termination of a loop. For example, a
loop may continue as long as the temperature is above 60 degrees.
Loop Variable: There is usually one variable that is used in forming the loop
condition. This variable is referred to as the loop variable. It is possible to have
more than one variable in the loop condition.

In general, there are two categories of loops: pretest loops and post-test loops.

 Pretest Loop
In a pretest loop, the condition gets evaluated at the beginning of the loop will not get
executed if the condition does not hold the very first time.

 Post-test Loop
In a post-test loop, the loop condition gets evaluated at the end of the loop cycle.
Therefore, the body of the loop will get executed at least once, regardless of the
condition. This is a major difference between a pretest loop and a post-test loop if the
problem description justifies the body of the loop be executed at least once.

References/Sources/Websites:
I.T. PROGRAMMING p. 161-173

Prepared by:
Mr. Fidel T. Sardonidos Jr.,LPT

You might also like