What is doing here? (Java)

I saw this piece of code somewhere inside. I wonder what it is for do.

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

        do {
            if (count % 2 == 0) {
                for (int j = 0; j < count; j++) {
                    System.out.print(j+1);

                    if (j < count-1) {
                        System.out.print(", ");
                    }
                }

                System.out.println();
            }

            count++;
        }
        while (count <= 5);
    }
}

By this I mean what exactly means do? What is its function? Any other information is also helpful.

+5
source share
5 answers

This is a do-while loop. Thus, he will do everything in the next block, while the number is less than or equal to 5. The difference between this and the normal while loop is that the condition is evaluated at the end of the cycle, and not at the beginning. Thus, the loop must be run at least once.

Sun tutorial during and during.

Oh, and in this case he will print:

1, 2
1, 2, 3, 4

: , , , , .

+6

while, , .

? while do.

? , , . -, ( do), , - , while stop.

+3

while, .

: while do-while

+2

do { ... } while(CONDITION)ensures that the block inside do will be executed at least once , even if the condition is not met, on the other hand, a whilestatment will never be executed strong> if the condition is not met

+1
source

This happens over time. do {...} while () is the loop at the end of which is conditon.

-1
source

All Articles