What they're doing there is for each iteration of i, they're multiplying the result by 2, i times.

The walkthrough would be

i = 0, e = 0, result not multiplied, output 2 to the power of 0 is 1

i = 1, e = 1, result multiplied one time by 2, 2 to the power of 1 is 2

etc

They're decrementing e there to "count i backwards" down to 0. E is reset each time, and will always enter the while loop on iterations after the first one, and will always exit the while loop once it counts down to zero.

Answer from dbillz on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_while_loop.asp
Java While Loop
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... Loops can execute a block of code as long as a specified condition is true. Loops are handy because they save time, reduce errors, and they make code more readable. The while loop repeats a block of code as long as the specified condition is true:
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-while-loop-with-examples
Java while Loop - GeeksforGeeks
Explanation: In the above example, the while loop runs until "i" is less than 6 and prints "Hello World" 5 times. Example: Calculating the Sum of Numbers from 1 to 10 with Java while Loop
Published   1 week ago
Discussions

While loop condition in java - Stack Overflow
I am working my way through "Java - A beginners guide by Herbert Schildt". I hope this question is not way too ridiculous. It is about a while loop condition, where the while loop is located inside a for loop. The code example is this one: More on stackoverflow.com
🌐 stackoverflow.com
JAVA - using FOR, WHILE and DO WHILE loops to sum 1 through 100 - Stack Overflow
As the title states, I have trouble understanding loops and have come up with a way to do a simple 1 through 100 sum, but like I said, the loops are causing me some confusion. I think I have the FO... More on stackoverflow.com
🌐 stackoverflow.com
What makes for-loops difficult for beginners?
The syntax of for loops in C-like languages is not exactly intuitive. Even the name "for" seems like a rather non-descriptive, meaningless word. I don't know how for loops are commonly taught, but perhaps it is common to see them introduced with examples like this: for (int i = 0; i < 10; ++i) print i; Now, it is true that the most common use of for loops is to repeat something a certain number of times like this, but if this is how for loops are introduced, then I can understand how they seem mysterious. What in the world is all that garbage syntax doing there for a simple counting loop? Why are there all of those semicolons, and why do you have to say ++i? Etc. It would be better, I think, to teach that the loop for (initialization; condition; update) statement; is (almost) equivalent to initialization; while (condition) { statement; update; } and then show several examples of the same code written in both of these ways to demonstrate and reinforce this equivalence. These examples should include not only the common case of repeating a statement a certain number of times, but also other uses of the for loop, such as finding the length of a C string (where the condition is like *p != '\0'). More on reddit.com
🌐 r/learnprogramming
7
2
March 27, 2013
for loop in Python and for loop in Java: differences
python only has for each loops More on reddit.com
🌐 r/learnprogramming
10
1
November 6, 2022
🌐
Tutorialspoint
tutorialspoint.com › java › java_while_loop.htm
Java - while Loop
The following diagram shows the flow diagram (execution process) of a while loop in Java - Here, key point of the while loop is that the loop might not ever run. When the expression is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed. In this example, we're showing the use of a while loop to print numbers starting from 10 to 19.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › while.html
The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
Therefore, the statements within the do block are always executed at least once, as shown in the following DoWhileDemo program: class DoWhileDemo { public static void main(String[] args){ int count = 1; do { System.out.println("Count is: " + count); count++; } while (count < 11); } }
🌐
DataCamp
datacamp.com › doc › java › java-while-loop
Java While Loop
This example demonstrates an infinite while loop, where the condition is always true. The break statement is used here to exit the loop, preventing it from running indefinitely. import java.util.Scanner; public class InputValidationExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number; System.out.println("Enter a number between 1 and 10:"); number = scanner.nextInt(); while (number < 1 || number > 10) { System.out.println("Invalid input.
🌐
CodeChef
codechef.com › blogs › loops-in-java
Loops in Java - For, While, Nested Loops
August 7, 2024 - Learn how to use Java loops effectively. This guide covers for loops, while loops, nested loops, and practical coding examples for beginners.
Find elsewhere
🌐
Programiz
programiz.com › java-programming › do-while-loop
Java while and do...while Loop
In this tutorial, we will learn how to use while and do while loop in Java with the help of examples.
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › java › java_do_while_loop.htm
Java - do...while Loop
The following diagram shows the flow diagram (execution process) of a do while loop in Java - In this example, we're showing the use of a while loop to print numbers starting from 10 to 19.
🌐
Scaler
scaler.com › home › topics › what is while loop in java?
What is While Loop in Java? - Scaler Topics
May 4, 2023 - Let's understand the while loop using a simple example. Problem Statement: Print "Hello World!" 10 times using while loop in java.
🌐
DataCamp
datacamp.com › doc › java › while
while Keyword in Java: Usage & Examples
This example demonstrates using a while loop to read user input until the user types "exit". The loop continues to prompt the user for input until the condition !input.equals("exit") becomes false.
🌐
IONOS
ionos.com › digital guide › websites › web development › while-loop java
How to use the while-loop in Java - IONOS
September 26, 2022 - A simple example of a while-loop in Java is a counter that counts up to a certain value. It does this exactly until the specified value (the ter­mi­na­tion condition) is reached.
🌐
Career Karma
careerkarma.com › blog › java › while loop java
While Loop Java: A Complete Guide | Career Karma
December 1, 2023 - This tutorial will discuss the basics of the while and do...while statements in Java, and will walk through a few examples to demonstrate these statements in a Java program. The while loop loops through a block of code as long as a specified condition evaluates to true.
🌐
BeginnersBook
beginnersbook.com › 2015 › 03 › while-loop-in-java-with-examples
While loop in Java with examples
Fourth iteration: value of i is 3, fourth element of the array represented by arr[3] is printed. After fourth iteration: value of i is 4, the condition i<4 returns false so the loop ends and the code inside body of while loop doesn’t execute. Practice the following java programs related to while loop:
🌐
WsCube Tech
wscubetech.com › resources › java › while-loop
Java While Loop: Syntax, Examples, Programs, Flowchart
September 2, 2025 - Learn about Java while loop with syntax, flowchart, and practical examples. Explore when to use while loop in Java with simple programs for better understanding.
🌐
Dremendo
dremendo.com › java-programming-tutorial › java-while-loop
while Loop in Java Programming | Dremendo
In the above example, we have run a while loop from 1 to 10. 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.
Top answer
1 of 3
7

- First to me Iterating and Looping are 2 different things.

Eg: Increment a variable till 5 is Looping.

    int count = 0;

    for (int i=0 ; i<5 ; i++){

        count = count + 1;

   }

Eg: Iterate over the Array to print out its values, is about Iteration

    int[] arr = {5,10,15,20,25};

    for (int i=0 ; i<arr.length ; i++){

        System.out.println(arr[i]);

   }

Now about all the Loops:

- Its always better to use For-Loop when you know the exact nos of time you gonna Loop, and if you are not sure of it go for While-Loop. Yes out there many geniuses can say that it can be done gracefully with both of them and i don't deny with them...but these are few things which makes me execute my program flawlessly...

For Loop :

int sum = 0; 

for (int i = 1; i <= 100; i++) {

  sum += i; 

}

 System.out.println("The sum is " + sum);

The Difference between While and Do-While is as Follows :

- While is a Entry Control Loop, Condition is checked in the Beginning before entering the loop.

- Do-While is a Exit Control Loop, Atleast once the block is always executed then the Condition is checked.

While Loop :

int sum = 0; 
int i = 0;       // i is 0 Here

    while (i<100) {

      sum += i; 
      i++;

    }

  System.out.println("The sum is " + sum);

do-While :

int sum = 0; 
int i = 0;      // i is 0 Here

    do{ 

      sum += i; 
       i++
    }while(i < 100; );

     System.out.println("The sum is " + sum);

From Java 5 we also have For-Each Loop to iterate over the Collections, even its handy with Arrays.

ArrayList<String> arr = new ArrayList<String>();

arr.add("Vivek");
arr.add("Is");
arr.add("Good");
arr.add("Boy");

for (String str : arr){         // str represents the value in each index of arr

    System.out.println(str);     

 }
2 of 3
5

Your for loop looks good.

A possible while loop to accomplish the same thing:

int sum = 0;
int i = 1;
while (i <= 100) {
    sum += i;
    i++;
}
System.out.println("The sum is " + sum);

A possible do while loop to accomplish the same thing:

int sum = 0;
int i = 1;
do {
    sum += i;
    i++;
} while (i <= 100);
System.out.println("The sum is " + sum);

The difference between the while and the do while is that, with the do while, at least one iteration is sure to occur.