How to use boolean in while loop with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        boolean b = true;
        
        int i = 0;
        while (b) {
            System.out.println(b);
            if (i++ == 3)
                b = false;
        }
        System.out.println(b);
    }
}
 
 
 
/*
run:
 
true
true
true
true
false
 
*/

 



answered Sep 9, 2020 by avibootz

Related questions

1 answer 154 views
1 answer 140 views
140 views asked Jun 14, 2019 by avibootz
1 answer 204 views
1 answer 228 views
1 answer 96 views
1 answer 100 views
...