| « Large Blockage | Stoned! » |
"While digging through some inherited code," writes Joe "M2tM" Smith, "I encountered a conditional masquerading as a loop."
"Thankfully, the fellow responsible is 'no longer with us', and I suppose this type of code stands as silent testament to why. This interesting loop is only created so the break keyword can be used as an elaborate GOTO."
bool bCreateModel = false;
for (;;)
{
if (!pModel)
{
bCreateModel = true;
break;
}
if (asModelParts.GetSize() != asModelPartsToLoad.GetSize())
{
bCreateModel = true;
break;
}
for (UINT32 i = 0; i < asModelPartsToLoad.GetSize(); ++i)
{
if (asModelPartsToLoad[i] != asModelParts[i])
{
bCreateModel = true;
break;
}
}
break;
}
|
No, you guys don't get it. This loop works like the "slingshot" maneuver that probes do to pick up speed before leaving orbit. Using a loop and then breaking out of it actually makes the code run faster!
|
| « Large Blockage | Stoned! » |