Ok so lets say I have boolean x = false. If I have a loop that says while (!x) does this mean while x is NOT false (true) or while x is NOT true (false)?
EDIT:
Ok I’m a bit confused, I think Im getting different answers. So if I have
int x=0;
boolean add1=false;
while (!add1){
x=1;
}
What is the final value of x in this case?
substituting the value of
xwe haveNow
!is the logical complement operator which inverts the value of a boolean so we getSo we keep looping till
xisfalseor till!xistrue.Note that the value of the variable can change in the body of the loop causing the looping to break. Consider a typical search program which uses a boolean variable called found:
UPDATE:
In your updated question
add1isfalseinitially so!add1istrueso we enter the while loop and changexto1. Since the value ofadd1does not change in the loop and there are nobreakandreturnyou keep looping infinitely.