As we’ve discovered within my preceding post, circles(for loop, while cycle) in coffee software development terminology or another s/W development languages are of use to run block of code several times. You are going to need to use circles in your selenium webdriver s/W evaluations quite often. We’ve previously learned for loop with different illustrations in my own preceding post. Today I would like to explain you while loop and do while cycle with useful illustrations in java software development terminology.
while Loop

Block of code that will be written in while loop may be executed till the state of while loop stays accurate.
Illustration :

int i = 0;
while(i<=3){
System.out.println(“Value Of Variable i Is “+i);
i++;
}

In above specified illustration of java software development terminology, while loop may be executed four occasions.

do while Loop

Same as while cycle, do while loop may be executed till the state results true.

Example :
int j=0;
do{
System.out.println(“Value Of Variable j Is “+j);
j=j-1; }while(j>0);
In above specified instance, while loop may be executed just one period.Big difference between while and do while loop
There’s one big difference between while and do while cycle.

while loop may assess state at the start of signal prevent so it is going to be executed as long as state (while(i3)) results true.
do while loop may assess state by the end of signal prevent so it is going to be ran minimal one period. After 1st period performance, it is going to assess the state and whether or not it returns true then signal of block may be ran once again or several period.

Downside of while or do while loop
If you are going to neglect to Increase or decrements varying value inside while loop block subsequently block of code may be ran countless period.
Illustration :
int i = 0;
while(i<=3){
System.out.println(“Value Of Variable i Is “+i);
}
Above provided while loop may be executed countless moment because variable isn’t incremented in while loop prevent.

Below provided complete illustration of while and do while loops will drive out your all uncertainties.

Straightforward operate it in your eclipse and check outcome.
public class Whileloop {
public static void main(String[] args) {
//while loop – will be executed till condition returns true.
System.out.println(“***while loop example***”);
int i = 0; //Variable initialization
while(i<=3){
System.out.println(“Value Of Variable i Is “+i);
i++;//Incrementing value of i by 1.
}
//do while loop – will be executed minimum one time without considering condition.
System.out.println(“”);
System.out.println(“***do while loop example***”);
int j=3; //Variable initialization
do{
System.out.println(“Value Of Variable j Is “+j);
j=j-1;//Decrementing value of j by 1;
}while(j>=0); }
}
Output of above given instance may be as holler.
***while loop example***
Value Of Variable i Is 0
Value Of Variable i Is 1
Value Of Variable i Is 2
Value Of Variable i Is 3***do while loop example***
Value Of Variable j Is 3
Value Of Variable j Is 2
Value Of Variable j Is 1
Value Of Variable j Is 0

Leave a Reply

Your email address will not be published. Required fields are marked *