Is code in episode 1 of New Game 2 actually an infinite loop?
The code is not an infinite loop but it is a bug.

There's two (possibly three) issues:


If no debufs are present no damage will be applied at all
Excessive damage will be applied if there is more than 1 debuf
If DestroyMe() immediately deletes the object and there are still m_debufs to be processed the loop will be executing over a deleted object and trashing memory. Most game engines have a destroy queue to work around this and more so that may not be an issue.


The application of damage should be outside the loop.

Here's the corrected function:

// the calculation of damage when attacked
void DestructibleActor::ReceiveDamage(float sourceDamage) 
{
    // apply debuffs
    auto resolvedDamage = sourceDamage;
    for (const auto&amp; debuf:m_debufs)
    {
        resolvedDamage = debuf.ApplyToDamage(resolvedDamage);
    }
    m_currentHealth -= resolvedDamage
    if (m_currentHealth &lt;= 0.f)
    {
        m_currentHealth = 0.f;
        DestroyMe();
    }
}