how to end a loop afetr 1 iteration

so i want to not run this if statement depite being true and in a called function, how would i do that? also, here is my current code for this:

IEnumerator spawner()
{
Debug.Log(“wave spawned”);
if (counter == 1)
{
for (int i = 0; i <= 2; i++)
{
yield return new WaitForSeconds(1.0f);
Instantiate(enemy, spawnpoint.position, spawnpoint.rotation);
Debug.Log(“1”);
}
}
so this function is called 4 times and i only want this to run once, without changing the value of the variable “counter”

alternatively, i knmow i could just change the amount of times this is called, but i also do not know hoe to do that, so if posible, i only want this coroutine to run once, despite also being called multiple times:

if (counter2 <= 0)
{
counter = counter + 1f;
Debug.Log(“e”);
counter2++;
StartCoroutine(spawner());
}

plz help me :[

You need to have a different condition which makes it evaluate as false under the desired circumstances.

It’s normal to have “compound” conditions in an if statement, which basically just means a condition with more than one part. E.g.

if (i == 1 && !firstRun)
{
 // Do stuff
}

The “&&” symbol in there is a condition which returns true only when the conditions on both sides of it also return true. The “!” symbol in there is a condition which returns true if the thing on its right is false, i.e. it inverts things.

So what I’ve written there is equivalent to “if i is 1 and firstRun is false”. Then you just need to set firstRun to the right value and things will behave as you want.

I highly recommend spending an hour or two properly learning how these things work, it’ll be well worth your time. Here’s a video link. I don’t know how good it is, but it’ll at least introduce you to some terms to look up.

you can use the break keyword.

for (int i = 0; i <= 2; i++)
{
yield return new WaitForSeconds(1.0f);
Instantiate(enemy, spawnpoint.position, spawnpoint.rotation);
Debug.Log("1");
break;
}

you also use return.

so just to clarify, && is the equivalent of an “and” logic gate, while putting an exclamation point before a value or a string or something is like having an inverter attatched, to get like a nand or a nor statement right? so would this chech out as an operator? nand = !&& not equal to = != ?