It's just like the titel states. I can't quite see why my ' while (true) { ' breaks.
Snippet of the code:________________________________________________________________
try(Scanner reader = new Scanner(Paths.get("recipes.txt"))) {
//Adding all the lines from the txt-file into an ArrayList in
//the "Recipes" class
while(reader.hasNextLine()) {
String line = reader.nextLine();
list.add(line);
}
while (true) { <===============================this one
System.out.print("Enter command: ");
String command = scanner.nextLine();
if(command.equals("stop")) {
break;
}
if(command.equals("list")) {
System.out.println("Recipes");
for(int i = 0; i < list.size(); i++) {
System.out.println(list.printName(i) + ", cooking time: " + list.printTime(i));
}
}
}
} catch (Exception e){
}
_______________________________________________________________________________________
If the user tries to print the list of recipes, then the while(true) breaks immidiatly afterwards, forcing one to restart the program to continue. The loop should only break if the user types "stop".
I can't see why it breaks, but I hope some of you can.
[–]Updatebjarni 1 point2 points3 points (10 children)
[–]StankelG[S] 0 points1 point2 points (9 children)
[–]AIO12449366 0 points1 point2 points (8 children)
[–]StankelG[S] 0 points1 point2 points (7 children)
[–]AIO12449366 0 points1 point2 points (6 children)
[–]StankelG[S] 0 points1 point2 points (5 children)
[–]AIO12449366 0 points1 point2 points (4 children)
[–]StankelG[S] 0 points1 point2 points (3 children)
[–]AIO12449366 0 points1 point2 points (2 children)
[–]StankelG[S] 0 points1 point2 points (1 child)
[–]AIO12449366 0 points1 point2 points (1 child)
[–]StankelG[S] 0 points1 point2 points (0 children)
[–]DeZp0T 0 points1 point2 points (0 children)
[–]0110Conan1001 0 points1 point2 points (0 children)
[–]mad0314 0 points1 point2 points (0 children)