+ 2

How do i break out of this loop

public static void newfunct() { boolean continueprg = true; while (continueprg= true){......... continueprg = false; break;} i tried this method but it couldn't break out from the loop

29th Sep 2017, 8:46 PM
Toni Sedjoah
Toni Sedjoah - avatar
3 Respuestas
+ 13
while (continueprg) {...} or while (continueprg==true) {...} == checks for equality = is the assignment operator, it sets your variable always back to true in your example.
29th Sep 2017, 8:52 PM
Tashi N
Tashi N - avatar
+ 6
or simply use while (continueprg){...}
5th Nov 2017, 8:13 PM
David Akhihiero
David Akhihiero - avatar
+ 4
You should use "==" in while condition ex. while (continueprg == true) { } or while (continueprg) { }
29th Sep 2017, 8:55 PM
AtoMX
AtoMX - avatar