I think they mean do this (insert number) times
But then again I haven’t reached that part so idk
So the basic concept of for-loops is this, you have a list, or an array, like the one below, then you repeat a piece of code inside it (the for loop) for each item in the array
soldiers = hero.findByType("soldier")
and let’s say we have 3 soldiers, and you want to command each one of them, but instead of specifying the index for each one like this (or maybe using while loops):
hero.command(soldiers, "attack", enemy) hero.command(soldiers, "attack", enemy) hero.command(soldiers, "attack", enemy)
you can use a for-in loop:
for soldier in soldiers: enemy = soldier.findNearestEnemy() if enemy: hero.command(soldier, "attack", enemy)
so it repeats the piece of code inside the loop, commanding every soldier you have.
Hope this helps, if you need anything else, you can ask.
Edit: the code above is python
thanks 2000 cahrssrsa
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.