Change it to

...
String input;
do
{
    input = scan.next();
    if(input.equals("enter") || input.equals("Enter"))
    {
        System.out.println("You have entered the house.");
    }
...
Answer from Dacaspex on Stack Overflow
🌐
Quora
quora.com › How-can-you-do-a-do-while-loops-in-Java-with-user-input-and-statement
How to do a do while loops in Java with user input and statement - Quora
... A do‑while loop in Java executes ... combined with user input (Scanner), it’s commonly used to prompt the user and continue until they choose to stop or enter a sentinel value....
🌐
Programiz
programiz.com › java-programming › do-while-loop
Java while and do...while Loop
In the above program, we have used the Scanner class to take input from the user. Here, nextInt() takes integer input from the user. The while loop continues until the user enters a negative number.
🌐
Delft Stack
delftstack.com › home › howto › java › java do while loop with user input
How to Create Java Do-While Loop With User Input | Delft Stack
February 2, 2024 - In this code, the do part is used to display the menu and take input from the user, while the conditional part depends on the user input.
🌐
W3Schools
w3schools.com › java › java_while_loop_do.asp
Java Do/While Loop
Summary: A do/while loop always runs at least once, even if the condition is false at the start. This is the key difference from a while loop, which would skip the code block completely in the same situation. This behavior makes do/while useful when you want something to happen at least once, such as showing a message or asking the user for input.
🌐
Programming Simplified
programmingsimplified.com › java › tutorial › java-while-loop
Java while loop | Programming Simplified
September 6, 2025 - We test a user input and if it's zero then we use "break" to exit or come out of the loop. ... class BreakWhileLoop { public static void main(String[] args) { int n; Scanner input = new Scanner(System.in); while (true) { // Condition in while loop is always true here System.out.println("Input ...
🌐
Coderanch
coderanch.com › t › 691813 › java › Loop-program-user-input
While-Loop for ending program from user input (Beginning Java forum at Coderanch)
March 17, 2018 - One often used approach where user input is required is to put the validation check and loop inside a method. Something like Then in the main body of your code you can call it like: And remove all your validation from your main body. Much cleaner. JavaRanch-FAQ HowToAskQuestionsOnJavaRanch ...
Find elsewhere
🌐
BeginwithJava
beginwithjava.com › java › loops › do-while-loop.html
Do While Loop in Java
The do while loop is similar to the while loop with an important difference: the do while loop performs a test after each execution of the loop body. import java.util.Scanner; // needed for Scanner Class /** * This program demonstrate do while loop. */ public class AddNumbers { public static void main(String[] args) { int value; // to hold data entered by the user int sum = 0; // initialize the sum char choice; // to hold 'y' or 'n' // Create a Scanner object for keyboard input...
🌐
W3Schools
w3schools.com › java › java_while_loop.asp
Java While Loop
In the next chapter, you will learn about the do while loop, which always runs the code at least once before checking the condition. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Linus Tech Tips
linustechtips.com › software › programming
How can I do a while loop with user input? (Java) - Programming - Linus Tech Tips
November 22, 2024 - I learned C++ before this, and that is why the loop is written that way Example: while (cin >> input) {...} I know that the way I'm trying to use the scanner doesn't work, because it requires the user to input twice, b...
🌐
YouTube
youtube.com › watch
Java Do While Loop Example Where User Prompts to Start Program Over - Appficial - YouTube
More videos coming soon, please SUBSCRIBE!A do-while loop is a post-test loop that executes its body of code at least once, and then repeats while the loop's...
Published   October 7, 2017
🌐
CodersLegacy
coderslegacy.com › home › learn java › java do while loop
Java do while loop - CodersLegacy
April 28, 2020 - The above code is designed to keep taking input from the user, adding them up in the variable sum until a negative number is input to terminate the loop. The use of the do while loop is important here as the code must run once so that the value of x can be obtained to be matched against the condition. This is contrast to the while loop, which would first check the condition and throw an error since x has no value at that point. If you don’t understand how we’re taking input here, see the Java input guide.
🌐
Sololearn
sololearn.com › en › Discuss › 2878470 › safety-first-java-do-while-loop-challenge
Safety first - java do while loop challenge | Sololearn: Learn to code for FREE!
January 4, 2018 - Below is the code that i have written ... System.out.println("Write password"); password ++; }while(password < 3); } } ... - First start the do loop....
🌐
SitePoint
sitepoint.com › blog › java › java’s while and do-while loops in five minutes
Java's While and Do-While Loops in Five Minutes — SitePoint
November 5, 2024 - Without a condition, the loop would become an infinite loop, which is generally undesirable. You can use a while loop to read user input until a valid input is received by placing the user input statement inside the loop.
🌐
Engineering LibreTexts
eng.libretexts.org › bookshelves › computer science › programming languages › think java - how to think like a computer scientist (downey) › 15: loops
15.6: The do-while Loop - Engineering LibreTexts
October 30, 2025 - We can use a do-while loop to keep ... in.nextDouble(); Although this code looks complicated, it is essentially only three steps: Display a prompt....
🌐
Coderanch
coderanch.com › t › 684625 › java › loop-user-input
While loop and user input (Beginning Java forum at Coderanch)
September 12, 2017 - Carey Brown wrote:You'll want to replace your a-- with edd.nextInt(). Every time through the loop you'll want to get another int. Also, variable names should begin with a lower case character, so it should be edd and not Edd. Alright but if i want to now use a text and number, and I want to print the text much as the number specifies, how do I do that? using While Thanks for your help! Hope you dont mind these noob questions. ... Mixing input as a number and as text potentially exposes you to one of the Scanner's gotchas.
🌐
Delft Stack
delftstack.com › home › howto › java › java while loop user input
How to Implement Java while Loop With User Input | Delft Stack
April 9, 2024 - The while loop checks if the input is not equal to “exit”. Inside the loop, we prompt the user to enter something and read their input using scanner.nextLine(). The loop continues until the user types “exit”, effectively allowing the ...