About 22,100,000 results
Open links in new tab
  1. java - How to repeat "if" statement when output is false - Stack Overflow

    Sep 25, 2015 · Idiomatic way of making an infinite loop in Java is while(true): System.out.print("Pick a number 1-10: "); int number = input.nextInt(); if (number == random) { System.out.println("Good!"); break; // This ends the loop. } else if (number > random) { System.out.println("Too Big"); } else if (number < random) { System.out.println("Too Small");

  2. java - Possible to repeat an if statement? - Stack Overflow

    Jan 18, 2015 · else { System.out.println("Make sure your spelling is correct."); valid = false; } } while (!valid); The loop will repeat every time the final else is hit as it will set valid = false;. You could also encapsulate this in a function, which would be …

  3. java - Repeating if else statement - Stack Overflow

    Aug 11, 2015 · You should look while or do-while in Java. You can get the idea from following example.. boolean status = true; String input = ""; while (status) { System.out.println("your input\n"); input = new Scanner(System.in).nextLine(); if (input.equals("valid")) { System.out.println("valid input"); status = false; } else { // not a valid input System ...

  4. Decision Making in Java (if, if-else, switch, break, continue, jump)

    Apr 16, 2025 · The if-else statement in Java is a powerful decision-making tool used to control the program's flow based on conditions. It executes one block of code if a condition is true and another block if the condition is false. In this article, we will learn Java if-else statement with examples. Example: [GF

  5. Java If ... Else - W3Schools

    Java has the following conditional statements: Use if to specify a block of code to be executed, if a specified condition is true; Use else to specify a block of code to be executed, if the same condition is false; Use else if to specify a new condition to test, if the first condition is false

  6. Loops in Java: Repeat your code multiple times

    When you want to repeat an operation or a code sequence several times, you should use a loop. The loop is used to repeat a statement or block of statements as long as a particular condition is true. The term “control flow statement” is often used …

  7. Flow control (if, else, switch, loops): Loops (repeat loops) : Course ...

    In Java, there are three main types of repetition loops: for, while and do-while. Let's explore each of them, understand how they work and learn how to apply them efficiently. The for loop is often used when the number of iterations is known. The syntax of the for loop is as follows: // Block of code to be repeated. Where:

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

    This article will look at the while loop in Java which is a conditional loop that repeats a code sequence until a certain condition is met. We will start by looking at how the while loop works and then focus on solving some examples together.

  9. Writing Clear and Efficient If-Else Statements with Multiple …

    Nov 27, 2023 · When working with if-else statements that have lots of conditions, it’s crucial to enhance the way we write the code so that it’s easy to read and maintain. In this article, we’ll explore several techniques to refine our syntax, accompanied by examples for a better understanding. 1. Importance of Clear and Efficient Code.

  10. How do I make my if conditions repeat in Java? - Stack Overflow

    May 23, 2014 · This is an easier way to go, using a do-while loop and a switch. Also fixed choice Scanner keyboard = new Scanner(System.in); double weight; int choice; System.out.println("What is your weight in pounds?"); weight = keyboard.nextDouble(); do { System.out.println("Which planet would you like to see your weight on?\n 1.

Refresh