About 6,740,000 results
Open links in new tab
  1. java - How can I input an if statement inside a while loop?

    Jul 30, 2016 · You basically have to check whether the number is less than 0. This is to be done while taking the input. You can just take the input inside a while loop in this manner: System.out.println("Enter a natural #"); while(true){ //loop runs until broken num = type.nextInt(); if(num>=0) break; System.out.println("Wrong input.

  2. Adding while loop with if statement java - Stack Overflow

    Mar 28, 2016 · You can use do-while loop to implement your functionality. Do-while will execute at least once and then checking continuous running expression is true or false. Your code has 2 responsibilities: 1. calculate the sum of 2 numeric inputs. 2. checks continuous calculating or not.

  3. java - Can if statements be nested in a while loop ... - Stack Overflow

    Apr 28, 2017 · I've been working with code that uses a do-while loop, and I wanted to add an if else statement into that loop. The do-while loop checks to see what text the user enters and will finish if the word 'exit' is entered.

  4. 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:

  5. Fixing Your Java if Statement Within a while Loop for Correct

    Learn how to troubleshoot and correct `if` statement logic inside a `while` loop in Java with this comprehensive guide to help your code run as expected. ---...more.

  6. Java If ... Else - W3Schools

    Use the if statement to specify a block of Java code to be executed if a condition is true. Syntax if ( condition ) { // block of code to be executed if the condition is true }

  7. Implementing conditional statements and loops in Java

    Apr 18, 2023 · Learn how to work with conditional statements and loops in Java, including if statements, switch statements, while loops, do-while loops, for loops, and for-each loops with examples.

  8. Conditional Statements and Loop Control in Java

    This lesson introduces Java's conditional statements (`if`, `else if`, `else`), as well as the `break` and `continue` statements within loops. It explains how these constructs can control the flow of a program, providing practical examples and use cases to illustrate their applications in developing efficient and robust code.

  9. 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, else the loop terminates. The while statement or loop continually executes a block of statements while a particular condition is true.

  10. Loops in Java ; break continue, if ,if..else, if...elseif...else ...

    Jan 26, 2018 · “while” loop allows code to be executed repeatedly based on a given Boolean condition. While loop executes set of lines until the Boolean condition becomes false. While loop check the boolean condition and if it evaluated to true, the …

Refresh