const int MAX_RETRIES = 5; void login() { for ( int idx = 0; idx < MAX_RETRIES; ++idx) if ( internal_login() == true) // we have a successful login return; throw "could not login"; } If MAX_RETRIES is a compile-time constant, a modern compiler could "unroll" the above loop, somewhat like this: void unrolled_login() { if ( internal_login() == true) return; if ( internal_login() == true) return; if ( internal_login() == true) return; if ( internal_login() == true) return; if ( internal_login() == true) return; throw "could not login"; } If MAX_RETRIES is a run-time constant, the compiler cannot optimize anything, since MAX_RETRIES could be any value |