Skip to content

JehanKandy/Java-While-and-DO-While-Loop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java-While-and-DO-While-Loop

Java While and DO While Loop

Code Explain

    public class while_loop {
        public static void main(String[] args) {
            int i = 0;

            //While loop
            while(i < 5){
                System.out.println("Hello");
                i++;
            }

            //do while loop

            int k = 0;
            do{
                System.out.println("hello Do while loop");
                k++;
            }
            while(k < 5);
        }    
    }

for starter code, Watch following link,
https://github.com/JehanKandy/First-Coding-with-JAVA

In oder to following Code,

    int i = 0;

    //While loop
    while(i < 5){
         System.out.println("Hello");
         i++;
    }

In oder to this code, firstly
I create a veriable named,

    int i = 0;

it is use for following code,

    while(i < 5){
         System.out.println("Hello");
         i++;
    }

In the while loop code I used,

    while(i < 5){

for count five times, as "Hello" word,

     System.out.println("Hello");
     i++;

and above code i use i++, because the while loop needs to increment after one by one


and in oder to DO WHILE LOOP

      //do while loop

      int k = 0;
      do{
           System.out.println("hello Do while loop");
           k++;
      }
      while(k < 5);

The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.


DEVELOPER : JEHANKANDY
THANK YOU

About

Java While and DO While Loop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages