Follow us on Facebook

Header Ads

Welcome to JAVA POint

Do-While loop With Example.(JAVA)

 

                                              Do-While loop With Example.


In the last instructional exercise, we talked about while circle. In this instructional exercise we will talk about do-while circle in java. do-while circle is like while circle, anyway there is a contrast between them: In while circle, condition is assessed before the execution of circle's body however in do-while circle condition is assessed after the execution of circle's body. 

Synatx  of do-while circle: 

do 

statement(s); 


} while(condition); 

How do-while circle functions? 

In the first place, the assertions inside circle execute and afterward the condition gets assessed, on the off chance that the condition return s valid, the control gets moved to the "do" else it leaps to the following assertion after do-while. 





do while circle java 

do-while circle model 

class DoWhileLoopExample { 

public static void main(String args[]){ 

int i=10; 

do{ 

System.out.println(i); 

I- - ; 

}while(i>1); 

Output: 

10 

2


Model: Iterating exhibit utilizing do-while Loops

Here we have a whole number cluster and we are repeating the exhibit and showing every component utilizing do-while circle. 

class DoWhileLoopExample2 { 

public static void main(String args[]){ 

int arr[]={2,11,45,9}; 

/I begins with 0 as exhibit record begins with 0

int i=0; 

do{ 

System.out.println(arr[i]); 

i++; 

}while(i<4); 

Output: 

11 

45 

9


0 Comments:

Post a Comment

C language and C++ progaming