+ 1
Why is the "break" outside the loop? (Safety first task)
I tried the "safety first" task. This is the code i wrote: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner read = new Scanner(System.in); int password; do { System.out.println("Write password"); password = read.nextInt(); } while (password != 8819); { if (password == 8819) { break; } } } } This is the message the console is giving me: ./Playground/Program.java:14: error: break outside switch or loop break; ^ 1 error But why is break outside the loop? And how do i fix this code?
1 Resposta
+ 1
Do check again.. You have do-while loop. Not the while loop.
Its out side of do-while.
Place 'if block', after input to password in loop.