Extend for loop by i + x

I have a for loop, calculating iterations with time involved.
I want the for loop dynamically adapt to this time value, as if the certain time-point in future prediction is not reached, the loop should run further.
Example:

for (int i = 0; i < TargetSteps; i++) { AccumulatedTime += Time.deltaTime; if (i == TargetSteps - 1 && AccumulatedTime < TargetTime) TargetSteps += 50; }

Can I extend a loop like this (it isn’t working in my case)? I have the loop running in a IEnumerator co-routine. Thanks in advance. ::: I know Time.deltaTime isn’t fix and not for prediction of future frames, it’s just used for this example on this case.

For loops are not meant to be dynamic, this can lead to many errors, you should use a do or a while loop,

Well, you can, however you have to be careful to not cause an infinite loop. You just over complicate the whole logic. If you want to repeat another 50 steps once you completed 50 steps, you may just use a nested loop instead. The intention is much clearer in that case.

Technically a for loop is the same as a while loop, but with two additions. It has an additional initialization section which allows you to declare and initialize local variables, then comes the normal while condition that is checked before each iteration. Finally there’s the “post processing” section that executes once an iteration has completed. That’s all there is to for loops.

A common usecase is to iterate through a linked list like this:

for(Node n = first; n != null; n = n.next)
{
}

There are other more esoteric usecases. However you should keep in mind that code should be readable and easy to understand. You don’t get any reward for cryptic or super short code unless you apply for the IOCCC.