While loops: lecture 118 - different approach

during the challenge I create an isLooping bool as per what Gary did, but I implemented it differently.

instead of having “do” to loop the waves and ending it with “while,” I replaced the “do” with “while isLooping == true” and didn’t end it with anything. This worked well, but will this ruin anything in the future?

Hi Seth,

Good job on developing your own solution. :slight_smile:

Since we are no clairvoyants, we do not know if your solution or any solution will ruin something in the future. There is always a chance that they will. However, as game developers, it’s our job to solve problems if they appear. As long as you knew what you were doing when you wrote this code, you will very likely be able to fix problems that might be caused by it. Trust in your skills!

See also:

1 Like

The main difference is what happens if isLooping starts off as false.
With a standard while loop your code to generate the enemies will not be run, whereas using a do-while loop will ensure that the waves are always instantiated at least once.

If your intention is to always have infinitely repeating enemy waves, then you can take either approach and you won’t really see any difference. However, you may start to see problems if you only want your waves to play through once - for instance, if you want to create a set number of enemies for a given the level.

Towards the end of the lecture, I test my solution with isLooping starting as either true or false so you can see the difference. If you run the same test using just a while-loop then you should witness the behaviour I mentioned above.

I hope that helps.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.