Control Flow Looping by Using While

Assoc. Prof. Leon Abdillah

Control Flow Looping by Using While

Leon Andretti Abdillah


—There may be a situation when we need to execute a block of code several number of times, and is often referred to as a “loop”. Other terminology could be “repetition” or “iteration”.

—Java has very flexible three looping mechanisms. You can use one of the following three loops:

1.while Loop…while Loop

3.for Loop


—A while loop is a control structure that allows you to repeat a task a certain number of times

—The while statement continually executes a block of statements while a particular condition is true.

—Its syntax can be expressed as:


while (boolean_expression) {




while ( test ) {




while (true){

// your code goes here


Java Code

package eLooping;

public class eLooping1WhileNumbers {

public static void main(String[] args) {
// TODO Auto-generated method stub

int count = 1;
while (count <= 5) {
System.out.println(“Number : ” + count);





C. H. Chuan. Introduction to Java Programming (for Novices & First-Time Programmers).  Retrieved from

L. A. Abdillah. (2013). Algorithms & Programming. Available:

L. A. Abdillah. (2014). Data Structures & Algorithms. Available:

L. A. Abdillah. (2016). Algorithms & Data Structures. Available:


Leave a Reply

Your email address will not be published. Required fields are marked *