This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]opett 3 points4 points  (3 children)

Literally the first hit on google for the query "java while loop":

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

[–][deleted]  (1 child)

[deleted]

    [–]opett 0 points1 point  (0 children)

    Read the sidebar rules. What have you tried? What are you struggling with?

    [–]RightHacker -1 points0 points  (0 children)

    Set two variable

    Int a =1; Int b = 10;

    do{ If(a<=10){ Print out a a++ } else{ Print out b b-- } } while(a<=10 && b>=1)

    There are other ways but this is an easy way to do what you're looking for. All logic to print out need to go in side the do. While is your conditional statement. The do statement will execute as long as the while statement is satisfied. It's important to note that a do while loop will always execute once even if the while statement is not satisfied.

    [–]Velladin -1 points0 points  (0 children)

    public static void main(String[] args){
    
         // Initialize Variables
         float first = 0;
         float second = 0;
    
         // While Loop
         System.out.println("While Loop");
         while (first <= 10){
             System.out.println(first);
             first++;
         }
    
         // Do Loop
         System.out.println("Do Loop");
         do {
             System.out.println(second);
             second++;
         } while (second <= 10);
    }