I have seen many pro*C programs, using a for loop to execute a set a statements "only once". For example,
for(i = 0; i < 1; i++)
{
EXEC SQL EXECUTE
DECLARE
/* some declarations here */
BEGIN
/* some PL/SQL code here */
END-EXEC;
}
Why is this for loop necessary ?
Just a wild guess: using such a loop might somehow simplify error handling when using
WHENEVER DO BREAK
orWHENEVER DO GOTO
:Consider the following code fragment:
If I'm not too wrong (don't have pro*C at hand right now), this would print 1 if the SQL query has completed without error. But 0 otherwise as we break before incrementing
i
.Somewhat at the margin of that, there is a common idiom using an infinite for loop and a
WHENEVER DO BREAK
statement to fetch results: