We will learn about the do keyword in java programming language
The do keyword is used to implement do-while loop in Java. It is used for execution of the block of statement at least one time in Java. When the boolean condition is executed, if the condition is true, the loop executes again. But, if boolean condition is false, the loop exits.
Remarks
Syntax of do statement
do { <statements> } while(condition)
The do loop iterates a block of statements with the while loop
do{ i++; }while(condition) // condition is test i<MaxNum
class DoKeywordinJava{ public static void main(String args[]){ int i=0; do{ System.out.println("i value is :"+i); i++; }while(i<10); } }
When the above code is compiled and executed, it will produce the following results
i value is :0 i value is :1 i value is :2 i value is :3 i value is :4 i value is :5 i value is :6 i value is :7 i value is :8 i value is :9
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
Array Data Structure: Definition, Types, Operations & Advantages Array Data Structure Introduction In this post,…
20 ways to subtract two numbers in Java In this article, we will discuss the…
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…
Python: Average of Odd & Even Numbers from User Input In this post, we will…