PROGRAMMING CONSTRUCTS
OR FLOW OF
INSTRUCTIONS
SEQUENCE
DECISION
ITERATION
TECHNOLOGY AND
LIVELIHOOD
EDUCATION
8
LOOP
GERARDO M. ROXAS
COMPUTER SCIENCE TEACHER
LOOP
a loop is a sequence of instructions that is
continually repeated until a certain condition
is reached.
LOOP
STATEMENTS
• FOR LOOP
• WHILE LOOP
• DO/WHILE LOOP
TECHNOLOGY AND
LIVELIHOOD
EDUCATION
8
FOR LOOP
GERARDO M. ROXAS
COMPUTER SCIENCE TEACHER
FOR LOOP
Use FOR LOOP when you know exactly how
many times you want to loop through
a block of code
FOR LOOP SYNTAX
SYNTAX OF FOR LOOP
for (statement 1; statement 2; statement 3) {
// code block to be executed
}
Statement 1 is executed (one time)
before the execution of the code block.
Statement 2 defines the condition for
executing the code block.
Statement 3 is executed (every time)
after the code block has been
executed.
Statement 1 sets a variable before the loop starts
Statement 2 defines the condition for the
loop to run (x must be less than 5).
If the condition is true, the loop will start over
again, if it is false, the loop will end.
Statement 3 increases a value (x++) each time
the code block in the loop has been executed.
What applications you have
encountered with application of
FOR Loop or with repetitive tasks?
How to use FOR Loop statement in
a computer program?
Create a For Loop program that
will print
the pattern 1, 2, 4, 8, 16, 32
and 64
Create a program that will print the
following pattern
Number 20
Number 18
Number 16
… up to
Number 0