forcase loop with where

Discussions about editing and cleaning data
Forum rules
New release: CSPro 8.0
Post Reply
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

forcase loop with where

Post by AriSilva »

The help says it executes 1 or more times, even if the where condition is not satisfied.
Don't you think this is a little bit tricky? For example
forcase BRUMA_75_DOMICS_DICT where DD00_SETOR = setor do
.....
endfor;
Even if there are no cases in the file where DD00_SETOR = setor, the loop is executed once.
So, in order to catch only the cases where DD00_SETOR = setor, process and count them, you have to duplicate the where condition inside the for loop with a
if DD00_SETOR <>setor then next; endif;
It seems to me that the syntax to force at least one execution should be something like
forcase
.....
where ...
endfor;

Like the do ... while
Best
Ari
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: forcase loop with where

Post by Gregory Martin »

When the help says that it "executes one or more statements," it means that you can have one or more than one statement within the loop. There is no guarantee that any statement in the loop will be executed, however, either because there are zero cases, or because of a where condition. For example this will not execute anything:
forcase MY_DICT where 1 = 0 do
Hopefully that clarifies things.
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: forcase loop with where

Post by AriSilva »

My fault, I read "one or more statements" and understood "one or more times"
My program had a bug and I thought that it was because of the forcase loop.
Best
Ari
Post Reply