Java while loop boolean evaluation -


i not sure if understand loop

boolean b = false; while(!b) { system.out.println(b); b = !b; } 

it returns false, loop executed once

but while(!b) set b= true ? !b = !false , b printed out?

the while (!b) condition not set b true.

the b = !b statement does.

that's why loop executes once.


translation in pseudo-code:

  • while not b (that is, while b false)
  • print b (so print false)
  • assign b not b, is, opposite of b (so assign b true)
  • next iteration of loop, b true, not b condition fails , loop terminates

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -