With Java 8 you can do this in one line.
IntStream.range(1, 11).forEach(number -> System.out.println(number));
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++; } } }
OneCompiler
onecompiler.com › posts › 3tb9838sm › java-program-to-print-numbers-from-1-to-10-using-while-loop
Java program to print numbers from 1 to 10 using while loop - Posts - OneCompiler
Following program shows you how to print numbers from 1 to 10 using while loop.
Top answer 1 of 2
2
With Java 8 you can do this in one line.
IntStream.range(1, 11).forEach(number -> System.out.println(number));
2 of 2
0
Assuming you must use i with an initial value of 10.
Copyfor(int i = 10; i > 0; i--) {
System.out.println(11-i);
}
// or using a while loop
int i = 10;
while(i > 0) {
System.out.println(11-i--);
}
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.
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 ...
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.
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
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++; }