Menu
Coddy logo textTech

Do-while Loop

Lesson 8 of 11 in Coddy's Control Statements in Java course.

The Java <i>do-while</i> loop is used to iterate a part of the program repeatedly, until the specified condition is true.

Example: Whenever we fill out a form for a job, we have to at least fill in the details once to check if we are eligible or not.

If the number of iterations is not fixed and you must execute the loop at least once, it is recommended to use a do-while loop.

Syntax:

do{    
	//code to be executed / loop body  
	//increment/decrement statement   
}while (condition);  
challenge icon

Challenge

Easy

Write a program using a do-while loop to print the value "Coddy" five times. There should be a space after each word, and there is no need to print on a new line. 

Try it yourself

class PrintCoddy {
    public static void printCoddy() {
        // Write code here
    }
}

All lessons in Control Statements in Java