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....
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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
Program code written using an enhanced for loop to traverse and access elements in an array can be rewritten using an indexed for loop or a while loop.
๐ŸŒ
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 ...
Find elsewhere
๐ŸŒ
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:
๐ŸŒ
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:
๐ŸŒ
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, ...
๐ŸŒ
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.
Top answer
1 of 5
3

The better question might be: Why wouldn't you want to use a FOR loop to iterate through an array? There are many ways to iterate through an Array or a collection and there is no law that states you have to use the FOR loop. In a lot of cases, it's simply the best to use for speed, ease of use, and readability. And yet, in other cases it is not:

The Array:

int[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

Display Array with the typical for loop:

for (int i = 0; i < array.length; i++) {
    System.out.println(array[i]);
}

Display Array with the enhanced for loop:

for(Integer num : array) {
    System.out.println(num);
}

Display Array with the do/while loop:

int i = 0;
do {
    System.out.println(array[i++]);
} while (i < array.length);

Display Array with the while loop:

int j = 0;
while (j < array.length) {
    System.out.println(array[j++]);
}

Display Array through Recursive Iteration:

iterateArray(array, 0);  // 0 is the start index.


// The 'iterateArray()' method:
private static int iterateArray(int[] array, int index) {
    System.out.println(array[index]);
    index++; 
    if (index == array.length) {
        return 0;
    }
    return iterateArray(array,index);
}

Display Array using Arrays.stream() (Java8+):

Arrays.stream(array).forEach(e->System.out.print(e + System.lineSeparator())); 

Display Array using IntStream (Java8+):

IntStream.range(0, array.length).mapToObj(index -> array[index]).forEach(System.out::println);

Choose your desired weapon....

2 of 5
1
Considering you have an array like : 
int[] array = {1,2,4,5,6};

You can use stream to iterate over it, apart from printing you can perform lot many thing over this array.

Arrays.stream(array).forEach(System.out::println);

Similarly you can do lot many action over collections as well:

List<String> myList = new ArrayList<>(); List
myList.add("A");
myList.add("B");
    

Stream.of(myList).forEach(System.out::println);

myList.forEach(System.out::println);

๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ java-and-array-iteration-what-beginners-need-to-know-22a44dd32afb
Java and Array Iteration โ€” What Beginners Need to Know
November 3, 2023 - 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.
๐ŸŒ
KoderHQ
koderhq.com โ€บ tutorial โ€บ java โ€บ iteration-control
Java for, while, do..while & foreach loops Tutorial | KoderHQ
Java provides us with four different kinds of loops: while - This loop iterates through a section of code while a condition is true.
๐ŸŒ
SitePoint
sitepoint.com โ€บ blog โ€บ java โ€บ javaโ€™s while and do-while loops in five minutes
Java's While and Do-While Loops in Five Minutes โ€” SitePoint
November 5, 2024 - You would need to initialize a counter variable, use it as the array index, and increment it within the loop. The loop condition would be that the counter is less than the array length.