Subject | Re: [ib-support] Breaking out of For Select...Do |
---|---|
Author | Joe Martinez |
Post date | 2003-05-06T10:48:36Z |
> >Example:That doesn't make sense to me. Wouldn't that WHILE loop just keep repeating
> >
> >for select MY_NUM from MY_TABLE into :THIS_NUM
> >do
> > BEGIN
> > THE_TOTAL = THE_TOTAL + THIS_NUM;
> > if (THE_TOTAL >= 500) then
> > /* somehow break out of the loop */
> > END
>
>Yup.
>
>for select MY_NUM from MY_TABLE into :THIS_NUM
>do
>BEGIN
> THE_TOTAL = 0;
> WHILE (THE_TOTAL < 500) DO
> BEGIN
> THE_TOTAL = THE_TOTAL + THIS_NUM;
> END
>END
for the same value of THIS_NUM? Let me be a bit more clear:
The table has the following values for THIS_NUM:
100
300
200
800
150
I want to loop through these rows.
1st iteration: MY_NUM = 100, THE_TOTAL = 100
2nd iteration: MY_NUM = 300, THE_TOTAL = 400
3rd iteration: MY_NUM = 200, THE_TOTAL = 600
At this point, THE_TOTAL is over 500, so I'm done. I don't even want to
loop through the 4th and 5th rows.
What you showed above looks to me like you're going through all of the
rows, and within each row seeing how many times MY_NUM goes into 500, which
is very different.
-Joe