(Week 04) Flow of Control (Repetition)
(Week 04) Flow of Control (Repetition)
Fundamentals of Programming
Semester 1 2015/2016
Chapter 4
Flow of Control (Repetition)
Contents
Introduction
while
do-while
for
break
continue
label
Common Error
Introduction
A repetition flow specifies that an action is to be
repeated while some condition remains true.
In Java, while, do-while and for statement are used for
the repetition flow.
There are two types of loop namely count-controlled loop
and sentinel-controlled loop.
Count-controlled loop executed the statements for a
fixed number of times.
Sentinel-controlled loop executed the statements
repeatedly until the sentinel is encountered.
while
A while statement executes a block of code repeatedly.
A condition controls how often the loop is executed.
while (condition)
statement;