"Why" Question about Unit 3 Lesson 18 Bubble 10a

Here’s what I did.

What I expect to happen: Alien continues moving around the screen after its first “circuit.”
What actually happens: Alien goes around the screen once, but it keeps moving up and off the screen at the end. I thought it would keep checking my conditionals as long as the Draw Loop keeps looping.

I understand how the exemplar solution works, but I’m curious about why in mine, it doesn’t keep looping around and checking the conditionals. Or maybe it does, just not in the way I expected.

I would appreciate any insight and am happy to clarify my question if needed.


Hello @msutton,

Interesting question. Here is how I see it…
It has to do with the order of the if statements. Although the draw loop is very fast, it doesn’t read all the if statements simultaneously. A computer still has to read code from the top to the bottom. The upper left corner for the alien is the final if statement and it doesn’t move to the “next” line of code (which would be the first if statement back at the top of the draw loop) because it never leaves the last if statement as that statement still evaluates to true. You can experiment and move around the if statements within the draw loop. This will cause the alien to leave the screen at different corners.

Hope that helps:)

Thanks, Michelle! That makes sense, but wow! Now I think the Draw Loop works differently than I thought it did. Why does it only go through the conditionals once? I thought it would go through them all and then loop through them again and again until the player hits Reset.