With Java 8 you can do this in one line.

IntStream.range(1, 11).forEach(number -> System.out.println(number));

Answer from Atul Kale on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-while-loop-with-examples
Java while Loop - GeeksforGeeks
... class whileLoop { public static void main(String args[]) { int i = 1; // test expression while (i < 6) { System.out.println("Hello World"); // update expression i++; } } } ... Explanation: In the above example, the while loop runs until ...
Published   3 weeks ago
🌐
IncludeHelp
includehelp.com › java-programs › print-numbers-from-1-to-10-using-while-loop.aspx
Java program to print numbers from 1 to 10 using while loop
package IncludeHelp; public class Print_1_To_10_UsingWhile { public static void main(String args[]) { //loop counter initialisation int i=1; //print statement System.out.println("Output is : "); //loop to print 1 to 10. while(i<=10) { System.out.println(i); i++; } } }
🌐
Sololearn
sololearn.com › en › Discuss › 850211 › how-to-print-a-number-from-10-to-1-using-do-while-loop-but-the-initial-value-shoudl-be-1
how to print a number from 10 to 1. Using do while loop. But The Initial value shoudl be 1 | Sololearn: Learn to code for FREE!
It's not that difficult. You just change counter to start at 10, and tell the while loop to decrease the value and flip the operator: #include<stdio.h> int main() { int counter = 10; do{ printf("%i\n", counter); } while(--counter > 0); return 0; }
🌐
Tutorialsinhand
tutorialsinhand.com › tutorials › java-programs › java-loop-programs › java-program-to-print-1-20.aspx
Java program to print numbers from 1 to 20 using for loops, while and do while loops
Java program to print numbers - In this chapter of our java programs tutorial, our task is to print numbers from 1 to 20 using java for loops, while loop and do while loop. Video tutorial for reference on java program to print numbers from 1 to 10 using for loop is also shared.
🌐
Dremendo
dremendo.com › java-programming-tutorial › java-do-while-loop
do while Loop in Java Programming | Dremendo
Each time when the loop runs, we print the value of the variable i on the screen on a separate line using System.out.println() statement. The loop ends when the value of i is more than 10.
🌐
Tutorialspoint
tutorialspoint.com › java › java_do_while_loop.htm
Java - do...while Loop
public class Test { public static void main(String args[]) { int x = 10; do { System.out.print("value of x : " + x ); x++; System.out.print("\n"); }while( x < 20 ); } } value of x : 10 value of x : 11 value of x : 12 value of x : 13 value of ...
🌐
Vik-20
vik-20.com › java › 1-10-the-do-while-loop
1-10 The do..while Loop – VIK-20.com
September 23, 2025 - Since we start oddNumber at 1 and add 2 each time the loop body iterates, it will never have a value of exactly 10 and the loop will iterate forever. To fix this logic error the condition should be more general: (oddNumber < 10). If your code ...
Find elsewhere
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java do while loop – tutorial with examples
Java Do While Loop - Tutorial With Examples
April 1, 2025 - Then, we have started a do while loop in which we have specified a do where the counter will be incremented by 1 after printing the value of ‘i’ and then a while condition i <=10, so it will keep on printing ‘i’ until the value reaches 11.
🌐
Upgrad
upgrad.com › home › blog › software development › do while loop in java: syntax, examples, and practical applications
Do-While Loop in Java: Examples, Applications & Tips 2025
September 10, 2025 - Output: "Iteration 2" is printed. Action: num is incremented by 1 again, so num becomes 3. Subsequent Iterations: This process repeats for num = 3, num = 4, and num = 5. The output for each will be: ... The counter num keeps increasing by 1 until it reaches the value 6. Final Condition Check: Once num = 6, the condition 6 <= 5 is checked and is false. Since the condition is false, the do while loop Java stops executing.
🌐
Programiz
programiz.com › java-programming › do-while-loop
Java while and do...while Loop
// infinite do...while loop int count = 1; do { // body of loop } while(count == 1) In the above programs, the textExpression is always true. Hence, the loop body will run for infinite times. The for loop is used when the number of iterations is known. For example, ... And while and do...while ...
🌐
AlgoCademy
algocademy.com › link
While Loop: Printing Numbers in Java
Nested loops allow for more complex iterations, such as iterating over multi-dimensional arrays. The break statement exits the loop prematurely, while the continue statement skips the current iteration and proceeds to the next one. int i = 3; while (i <= 10) { if (i == 7) { i++; continue; // Skip the number 7 } System.out.println(i); i++; }
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-do-while-loop
Java do while loop | DigitalOcean
August 3, 2022 - Here is a simple java do-while loop example to print numbers from 5 to 10.
🌐
Sanfoundry
sanfoundry.com › java-program-display-numbers-1-10-using-for-loop
For Loop Program in Java with Examples - Sanfoundry
March 18, 2023 - 7. The “println()” method prints the value followed by a newline character to print each number on a separate line. 8. When executed, the program outputs the numbers 1 to 10 on separate lines.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-do-while-loop-with-examples
Java Do While Loop - GeeksforGeeks
The variable c is initialized to 1 before entering the loop. The do block executes first and prints "Hello World", ensuring the loop runs at least once. After printing, c is incremented using c++. The loop continues as long as the condition c < 6 is true, resulting in the message being printed 5 times. ... import java.io.*; class GFG { public static void main(String[] args) { int c = 1; do { // Only single statement in do block System.out.println("Hello GFG!"); } // This condition is false, so the loop will execute only once while (c >= 3); } }
Published   3 weeks ago
🌐
YouTube
youtube.com › watch
Print 1 To 10 Using While Loop In Java - YouTube
Want to print 1 to 10 using a while loop in Java? This video teaches you how to do exactly that. First, you have to set up the loop counter variable properly...
Published   May 1, 2024
🌐
OneCompiler
onecompiler.com › java › 3wkt7bwkr
Print numbers 1 to 10 each number in a separate line using java - Java - OneCompiler
Usually for loop is preferred when number of iterations is known in advance. for(Initialization; Condition; Increment/decrement){ //code } While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance. ... Do-while is also used to iterate a set of statements based on a condition.
🌐
W3Schools
w3schools.com › java › java_while_loop.asp
Java While Loop
This example counts from 3 to 1, and then prints "Happy New Year!!" at the end: int countdown = 3; while (countdown > 0) { System.out.println(countdown); countdown--; } System.out.println("Happy New Year!!"); ... In the previous examples, the condition was true at the start, so the loop ran one or more times. But if the condition is false at the beginning, the code inside the loop will never run: int i = 10; while (i < 5) { System.out.println("This will never be printed"); i++; }
🌐
Iqra Technology
iqratechnology.com › academy › java › java-basic › java-while-do-while-loop
Master Java Loops: While & Do-While with Examples
June 13, 2025 - Inside the loop, use a switch statement ... motivational message for grades A and B. 8. Print Prime Numbers: Use a while loop to print all prime numbers between 1 and 100....