About 20,700,000 results
Open links in new tab
  1. Java While Loop - W3Schools

    Loops can execute a block of code as long as a specified condition is reached. Loops are handy because they save time, reduce errors, and they make code more readable. The while loop loops through a block of code as long as a specified condition is true:

  2. What condition does while(true) test? When is it true and false?

    The while loop will iterate while the user input can't be parsed to an int. When the user input is parsed to int the loop exits by returning the number entered by the user.

  3. java - Are "while (true)" loops so bad? - Stack Overflow

    Jul 28, 2011 · As an example of where it's clearer to use break than a flag, consider: doStuffNeededAtStartOfLoop(); int input = getSomeInput(); if (testCondition(input)) break; actOnInput(input); Now let's force it to use a flag: doStuffNeededAtStartOfLoop(); int input = getSomeInput(); if (testCondition(input)) running = false; else. actOnInput(input);

  4. Java while Loop - GeeksforGeeks

    Nov 11, 2024 · Java while loop is a control flow statement used to execute the block of statements repeatedly until the given condition evaluates to false. Once the condition becomes false, the line immediately after the loop in the program is executed. Let’s go through a simple example of a Java while loop:

  5. Java while Loop (with Examples) - HowToDoInJava

    Jan 2, 2023 · The while loop in Java continually executes a block of statements until a particular condition evaluates to true. As soon as the condition becomes false , the while loop terminates. As a best practice, if the number of iterations is not known at …

  6. While loop in Java: repeats the code multiple times - Learn Java

    Let’s see a few examples of how to use a while loop in Java. The following examples show how to use the while loop to perform one or more operations as long a the condition is true. System.out.println("Hello, World!");

  7. Java While Loop: Syntax, Examples and Common Pitfalls

    Dec 19, 2024 · The while loop in Java is a control flow statement used to repeatedly execute a block of code as long as a specified condition is true. It is one of the most fundamental looping constructs in Java, making it ideal for situations where the number of iterations is not fixed or known beforehand.

  8. Java While Loop - w3resource

    Aug 19, 2022 · In Java, a while loop consists of the keyword while followed by a Boolean expression within parentheses, followed by the body of the loop, which can be a single statement or a block of statements surrounded by curly braces. You can use a while loop when you need to perform a task a predetermined number of times.

  9. Java While Loop - Coding Learn Easy

    A while loop in Java repeatedly executes a block of code as long as a specified condition evaluates to true. Once the condition becomes false , the loop stops executing. The syntax for a while loop is:

  10. Java while Loop - Java Guides

    The while loop in Java is a powerful control flow statement for performing repeated tasks based on a condition. Understanding how to use the while loop effectively, including its variations with break and continue statements, as well as nested loops, is …

Refresh