Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Julian Rios
Julian Rios
3,458 Points

What is !isDunked set to in the while loop expression at the beginning? Is it still false like in the initialization?

I am just confused on if the isDunked variable changes to true when the ! operand is added to the beginning of the variable. or if it is just a way of reading variables as false.

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

the ! is negating whatever it is put in front of, so if the variable is initialized as false, !false is true, which will allow the while loop to enter and run, and it will run until something changes the variable to true, at which point !true would be false, and the while loop would exit

Julian Rios
Julian Rios
3,458 Points

What I am not seeing is this. Wouldn't !isDunked && ballsThrown <=3 both need to be false in order to run the code block below?

while (!isDunked && ballsThrown <= 3) {
      console.printf("Try #%d ...%n", ballsThrown + 1);
      isDunked = skill.nextBoolean();
      ballsThrown++;
    }