Both the native (DBPro)
wait and
sleep commands use
busy waiting, which sucks up a lot of CPU power and as a result drains battery pretty quickly on mobile devices. Other than that, a properly implemented 'wait' command can be handy in procedural (as opposed to real-time) applications, where you don't need anything to happen during that time period.
Quote: "If you goto from a For...Next loop, you invariably leave garbage behind, because the loop is never completing, it's probably storing a pointer back to that loop every time you goto from it"
Pretty sure this doesn't happen in DBPro; it's not necessary to store a pointer to the start of the loop since it has a fixed address. It should be safe to jump out of any standard loop. Conversely, jumping
into a any loop is a very bad idea since it needs to initialize the loop variables first.
Admittedly
goto doesn't have very many uses (and is potentially dangerous to use in DBPro since labels aren't scope-unique), but I've found a few uses where it is better than some alternatives. If I remember correctly, these two cases (C++):
1. In self-contained functions that require their own cleanup routine:
void UtilityFunction()
{
if (!InitCheck1())
goto cleanup;
if (!InitCheck2())
goto cleanup;
if (!InitCheck3())
goto cleanup;
if (!InitCheck4())
goto cleanup;
// Perform operation
...
cleanup:
// Perform cleanup
...
}
In a proper implementation of this function operations would occur between the checks, requiring cleanup at the end of the function. You could alternately stack the IF statements inside each other, but this would look messy and would require that you write separate cleanup code after each step.
2. Multiple nested loops where an abstract problem occurs:
for (x = 0; x < 10; x++)
{
for (y = 0; y < 10; y++)
{
for (z = 0; z < 10; z++)
{
if (SomethingWentWrong())
goto fail_and_cleanup;
}
}
}
fail_and_cleanup:
...
You could use
break (exit) and store an error flag in a variable which is then checked by each loop, but that would require more unnecessary code.
In both of these examples
goto is beneficial and has no drawbacks.
Your erased has been moderated by signature.