3Q 10 Week 4-5
3Q 10 Week 4-5
3Q 10 Week 4-5
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.
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.
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