Top "While-loop" questions

A while loop is a control structure used in many programming languages to continuously execute a set of instructions as long as a particular condition is met.

Java - Does returning a value break a loop?

I'm writing some code that basically follows the following format: public static boolean isIncluded(E element) { Node<E> …

java while-loop boolean return singly-linked-list
How to pipe input to a Bash while loop and preserve variables after loop ends

Bash allows to use: cat <(echo "$FILECONTENT") Bash also allow to use: while read i; do echo $i; done &…

bash while-loop stdin pipe
Which is faster: while(1) or while(2)?

This was an interview question asked by a senior manager. Which is faster? while(1) { // Some code } or while(2) { //Some code } …

c performance while-loop
Break statement inside two while loops

Let's say I have this: while(a){ while(b){ if(b == 10) break; } } Question: Will the break statement take me out …

java while-loop break
Ending an infinite while loop

I currently have code that basically runs an infinite while loop to collect data from users. Constantly updating dictionaries/lists …

python while-loop infinite-loop
Java for loop vs. while loop. Performance difference?

Assume i have the following code, there are three for loop to do something. Would it run fast if i …

java for-loop while-loop
Is while (true) with break bad programming practice?

I often use this code pattern: while(true) { //do something if(<some condition>) { break; } } Another programmer told me …

while-loop readability
Finding factors of a given integer

I have something like this down: int f = 120; for(int ff = 1; ff <= f; ff++){ while (f % ff != 0){ } Is there …

java for-loop integer while-loop factors
Run code for x seconds in Java?

I'd like to write a java while loop that will iterate for 15 seconds. One way I thought to do this …

java time while-loop
Assign variable in while loop condition in Python?

I just came across this piece of code while 1: line = data.readline() if not line: break #... and thought, there must …

python while-loop variable-assignment