One main difference is while
loops are best suited when you do not know ahead of time the number of iterations that you need to do. When you know this before entering the loop you can use for
loop.
More Related Contents:
- Repeat the “if” statement if it has to go to the “else” statement
- Java – What would cause a while-loop to execute, even when false?
- What is a NumberFormatException and how can I fix it?
- Declaring variables inside or outside of a loop
- How to get out of while loop in java with Scanner method “hasNext” as condition?
- Are “while(true)” loops so bad? [closed]
- Timer & TimerTask versus Thread + sleep in Java
- How do I exit a while loop in Java?
- Java for loop vs. while loop. Performance difference?
- Java: for(;;) vs. while(true)
- How to use .nextInt() and hasNextInt() in a while loop
- Scanner input validation in while loop
- Whats wrong with this while loop? [duplicate]
- Java How can I break a while loop under a switch statement?
- Does Java recognize infinite loops?
- How to optimize for-comprehensions and loops in Scala?
- Java – Does returning a value break a loop?
- Java InputMismatchException
- Run code for x seconds in Java?
- How can I override next() for jagged array java?
- Sort on a string that may contain a number
- Restricting JTextField input to Integers [duplicate]
- What is the difference between Integer and int in Java?
- Spring MVC: Complex object as GET @RequestParam
- Connection to Db dies after >4
- Input and Output binary streams using JERSEY?
- Using GZIP compression with Spring Boot/MVC/JavaConfig with RESTful
- How to determine if a number is a prime with regex?
- Import Google Play Services library in Android Studio
- Error setting a default null value for an annotation’s field