int i = 0;                            // array starts from 0
int [] array = new int[100];          // create larger array
while(i < array.length && sum <= 100) // i should be less then length
                                      // && instead of ||
{
   System.out.println("Write in the " + i + " number") ; 
   array[i] = input.nextInt();
   sum += array[i];                   // += instead of =+
   System.out.println("sum is " + sum);
   i++;                               // increment i 
}  

Ideone DEMO

Answer from Ilya on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_arrays_loop.asp
Java Loop Through an Array
Java Examples Java Videos Java ... Java Certificate ... You can loop through the array elements with the for loop, and use the length property to specify how many times the loop should run....
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-do-you-execute-a-while-loop-in-java
How do you execute a 'while' loop in Java?
Then we define an index variable to iterate over the array. The while loop, from lines 6 to 9, is run till index becomes equal to len indicating that the entire array is traversed.
๐ŸŒ
Funnel Garden
funnelgarden.com โ€บ java-for-loop
Java For Loop, For-Each Loop, While, Do-While Loop (ULTIMATE GUIDE)
Their structure follows this order ... condition) To loop over an integer array with a while loop, we initialize a local variable to 0, which is the first array index....
๐ŸŒ
Instructables
instructables.com โ€บ design โ€บ software
How to Use a While Loop to Iterate an Array in Java : 9 Steps - Instructables
July 22, 2022 - How to Use a While Loop to Iterate an Array in Java: Today I will be showing you how to use Java to create a While loop that can be used to iterate through a list of numbers or words. This concept is for entry-level programmers and anyone who wants to get a quick brush-up on Java Loops and arrays.
๐ŸŒ
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 ...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_while_loop.asp
Java While Loop
How Tos Add Two Numbers Swap Two ... Number ArrayList Loop HashMap Loop Loop Through an Enum ... assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String ...
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ java โ€บ java-array โ€บ java-array-while-loop
Java Array - While Loop
November 23, 2020 - Java Array While Loop - To access elements of an array using while loop, use index and traverse the loop from start to end or end to start by incrementing or decrementing the index respectively.
Find elsewhere
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ csjava โ€บ Unit7-Arrays โ€บ topic-7-3-arrays-with-foreach.html
7.3. Enhanced For-Loop (For-Each) for Arrays โ€” CS Java
To set up a for-each loop, use for (type variable : arrayname) where the type is the type for elements in the array, and read it as โ€œfor each variable value in arraynameโ€. for (type item: array) { //statements using item; } See the examples below in Java that loop through an int and a String ...
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2016 โ€บ 02 โ€บ how-to-loop-through-array-in-java-with.html
How to loop through an Array in Java? Example Tutorial
In short, use for loop if you need to hold the counter which points to current index and uses enhanced for loop if you just want to iterate over all elements of an array. Use while and do-while if your looping depends upon the element of an array, ...
๐ŸŒ
CodingBat
codingbat.com โ€บ doc โ€บ java-array-loops.html
CodingBat Java Arrays and Loops
In contrast, Java Lists can grow and shrink over time -- this is a big feature that Lists have that arrays do not. The length of an array can be accessed as a special ".length" attribute. For example, with the above "values" array, we can access the size of the array as "values.length". It is common to use a 0...length-1 for-loop to iterate over all the elements in array:
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ java_while_loop.htm
Java - while Loop
In this example, we're showing the use of a while loop to print contents of an array. Here we're creating an array of integers as numbers and initialized it some values. We've created a variable named index to represent index of the array while iterating it. In while loop we're checking the index to be less than size of the array and printed the element of the array using index notation.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java flow control โ€บ while loop
Java while Loop (with Examples) - HowToDoInJava
January 2, 2023 - As soon as, the counter reaches 6, the loop terminates. int counter = 1; while (counter <= 5) { System.out.println(counter); counter++; } Program output. ... The following Java program iterates over an ArrayList using its iterator in the while loop.
๐ŸŒ
CodingTechRoom
codingtechroom.com โ€บ question โ€บ -java-while-loop-array
How to Iterate Through a Java Array Using a While Loop - CodingTechRoom
Use a while loop to traverse the array, ensuring to increment the index variable within the loop body.
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ java-and-array-iteration-what-beginners-need-to-know-22a44dd32afb
Java and Array Iteration โ€” What Beginners Need to Know
June 17, 2024 - The condition i < numbers.length ensures that the loop continues as long as i is less than the length of the array. The index i is incremented by 1 in each iteration. ... Flexibility: The while loop is useful when the number of iterations is not known beforehand or when the loop needs to be controlled by a more complex condition.
๐ŸŒ
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 ย  November 11, 2024
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ loops-in-java
Java Loops - GeeksforGeeks
This is one of the most common mistakes while implementing any sort of looping is that it may not ever exit, that is the loop runs for infinite time. This happens when the condition fails for some reason. ... Example: Here, both the examples demonstrates the infinite loops. ... // Java program to demonstrate // the infinite for loop import java.io.*; class Geeks { public static void main(String[] args) { for (int i = 0; i < 5; i--) { System.out.println( "This loop will run forever"); } } }
Published ย  August 10, 2025
๐ŸŒ
Zero To Mastery
zerotomastery.io โ€บ blog โ€บ enhanced-for-loop-java
How To Use Enhanced For Loops In Java (aka 'foreach') | Zero To Mastery
January 26, 2024 - Loops are the backbone of many ... the (do) while loop. Always improving, Java 5 introduced the enhanced for loop as a part of its syntax enrichment. The enhanced for loop, otherwise known as a foreach loop, offers a simplified way to iterate over collections and arrays...