About 51 results
Open links in new tab
  1. Using while loop in java - Stack Overflow

    Here's a simple change, instead of using a while loop, you could try using a do while loop! I know this is late, but I'm learning along the way and I'm taking this as a practise!

  2. java - Declaring variables inside or outside of a loop - Stack Overflow

    Jan 10, 2012 · The scope of local variables should always be the smallest possible. In your example I presume str is not used outside of the while loop, otherwise you would not be asking the question, …

  3. How do I exit a while loop in Java? - Stack Overflow

    Oct 31, 2011 · 2 Take a look at the Java™ Tutorials by Oracle. But basically, as dacwe said, use break. If you can it is often clearer to avoid using break and put the check as a condition of the while loop, …

  4. java - when to use while loop rather than for loop - Stack Overflow

    I am learning java as well android. Almost everything that we can perform by while loop those things we can do in for loop. I found a simple condition where using while loop is better than for lo...

  5. java - Try-Catch inside While Loop - Stack Overflow

    Jul 21, 2014 · 0 Why use a loop with a try and catch? My advice would be to always use a try and catch with either a while or do while loop, so you can ask the user to repeat his/her input. It also depends …

  6. java - When would a do-while loop be the better than a while-loop ...

    Dec 9, 2013 · In a while loop, the condition is tested before it executes code in the loop. In a do while loop, the code is executed before the condition is tested, resulting in the code always being executed …

  7. Triangle pattern in Java with while loop - Stack Overflow

    Mar 30, 2022 · Triangle pattern in Java with while loop Asked 3 years, 10 months ago Modified 3 years, 5 months ago Viewed 2k times

  8. java - How do I continue to loop until the user wants to quit? - Stack ...

    Jul 16, 2021 · You can simply use while loop until the user wants to quit. Add a condition on user prompt input and if the user tries to quit, just break the loop. Also, you're exiting the system if the user gives …

  9. Why should wait() always be called inside a loop - Stack Overflow

    Oct 1, 2018 · A while loop is the best choice for checking the condition predicate both before and after invoking wait (). Similarly, the await () method of the Condition interface also must be invoked inside …

  10. java - Is it possible to reenter a while loop after it has been broken ...

    It jumps back to the top of the while loop, but only when it is declared inside of that loop. Is there some way of achieving the same effect after exiting the loop completely?