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

C# C# Objects Loops and Final Touches Foreach Loops

Dominik Huber
Dominik Huber
4,631 Points

Why break out from the loop if we do damage to one of the invaders, when there are more invaders in the array?

So basically he wrote if the invader is in range and is also active. We give him 1 damage and then exit the loop. But why? We have just damaged one invader. Shouldn't we check also the other invaders in the array?

Can someone please clarify this for me a bit further?

Thx!

1 Answer

Steven Parker
Steven Parker
229,732 Points

This is explained in the video when the instructor says, "Finally let's handicap the towers a bit by only letting them shoot at one tower at a time."

I assume this is done because if each tower could hit every invader in range during each turn, the towers would always win very quickly.