While Loop
Lesson 9 of 11 in Coddy's Control Statements in Java course.
The while loop is used to iterate a part of the program repeatedly until the specified condition is true; if the condition is false, the loop automatically stops.
While loop is a kind of countdown like you do on New Year's Eve from ten to one.
Syntax:
while (condition){
// code to be executed
// Increment / decrement statement
} Challenge
EasyWrite a simple program to print "Hello World! " 5 times using the while loop. Make sure you have space after the exclamation mark and do not print on a new line.
Try it yourself
class Hello {
public static void hello() {
// Write code here
}
}All lessons in Control Statements in Java
1What are Control Statements?
Introduction2Decision Making Statments
Simple if Statementif-else Statementif-else-if StatementNested if-StatementSwitch Case Statement