A survival game’s update loop may spawn enemies, move them, handle collisions, and check for game over. Counting branches in that loop is a practical complexity metric: each `if` or other conditional adds a path whose condition and outcome must be understood. A branch-free sequence makes the work that runs on every tick easier to see. section 11.0
Listing 11.1 The Tick() function without any branches
public static void Tick()
{
spawnEnemy();
moveEnemies();
checkEnemyOutOfBounds();
doEnemyToEnemyCollision();
movePlayer();
checkGameOver();
}This `Tick()` calls its gameplay steps in sequence, without deciding whether to call each one. section 11.0
Listing 11.2 The Tick() function with a lot of branches
public static void Tick()
{
if(canSpawnEnemy())
spawnEnemy();
if(canMoveEnemies())
moveEnemies();
if(shouldBoundCheck())
checkEnemyOutOfBounds();
if(collisionsOn())
doEnemyToEnemyCollision();
if(canMovePlayer())
movePlayer();
checkGameOver();
}Compare the conditional version: debugging now requires checking which steps ran and why. section 11.0
Branch count is a useful signal, not a complete score for a codebase. Separating alive and dead enemy indices removes a status check from each enemy iteration, but introduces arrays and index bookkeeping. The trade-off can be worthwhile when it simplifies a frequently run loop. Branches in hot code may also cost CPU work, especially when their outcomes are unpredictable; measure performance rather than assuming every conditional needs removal. section 11.0 section 11.7
Look beyond visible conditionals. Repeated Unity `GameObject` null checks can perform extra native-lifetime work; checking assets when they load and controlling object lifetimes can avoid unnecessary checks during play. Conversely, reducing branch count is not a reason to add architecture indiscriminately: a full ECS conversion can create more components, systems, and conversion work than an array-based game needs. section 11.7 section 12.3
For UI that behaves differently across menus, separate scripts can be easier to debug than one shared script full of cases. Keep shared appearance in assets and data. The aim is not zero branches everywhere; it is code whose paths, data, and maintenance costs are easy to see. section 11.5 section 1.1
