The while keyword in Java programming language
- Home
- Keyword in Java
- The while keyword in Java programming language
- On
- By
- 0 Comment
- Categories: Keyword in Java, While loop
The while keyword in Java programming language
The while keyword in Java programming language
We will learn about the while keyword in Java programming language
In Java programming language, while is a keyword used in the while and do while loop. The while specifies a loop that executes a block of statements repeatedly until given condition(Boolean expression) is true. In the while loop test expression similar to if condition (based in Boolean expression-returns true or false)
Syntax
Syntax of the while keyword
while(condition){ statement(s) //block of statements }
Example
Example of using while keyword
while(i>=10){ //boolean expression System.out.println(i); // display statements i--; // increment statement; }
The logic executes a block of statements until the boolean expression returns true. It is terminated when the boolean expression returns as false
Program
class WhileInJava{ public static void main(String args[]){ int i=1; //variable declaration while(i<=5) { //using while keyword to while loop //display the output System.out.println("The value of i is :"+i); i++; //updating statements } } }
When the above code is compiled and executed, it will produce the following results
The value of i is :1 The value of i is :2 The value of i is :3 The value of i is :4 The value of i is :5
Similar post
There are other Java language keywords that are similar to this keyword
static keyword in Java language
extends keyword in Java language
Suggested for you
Usage of final keyword in Java
Finally keyword in Java language
for keyword in the Java language