java - stop code if the condition is true -
the problem @ while loop, there comment
bufferedreader user = new bufferedreader(new filereader( "c:\\users\\ionut\\workspace\\tbot\\persoane.txt")); string line; while ((line = user.readline()) != null) { if (line.tolowercase().contains(nume.tolowercase())) { system.out.println("ce mai faci " + nume + "?"); ceva = scanin.nextline(); //here want stop if status true, show message , go ahead , execute rest of code } }
basically 2 mutual solutions:
1- using break
:
while ((line = user.readline()) != null) { if (line.tolowercase().contains(nume.tolowercase())) { system.out.println("ce mai faci " + nume + "?"); ceva = scanin.nextline(); break; // exists closest loop } }
2- using boolean
flag:
boolean stop = false; while (!stop && (line = user.readline()) != null) { if (line.tolowercase().contains(nume.tolowercase())) { system.out.println("ce mai faci " + nume + "?"); ceva = scanin.nextline(); stop = true; } }
java
No comments:
Post a Comment