how deluge statement usage limits are count

how deluge statement usage limits are count

Hi,
There is a limit of 5000 statements in a script, for example when I process an on load or submit script.
In an earlier forum post I found this text:

But if you have a "for each" loop within your action script, the number of times the tasks are executed depends on "the number of records iterated the number of tasks".  For example, if you have 500 records to be iterated and 3 tasks, the total number of executable statements for this action is 1500.  It is not the number of times they are triggered by users or it is not a daily/monthly limit. 

That is clear. But I would like to understand this a little better because I think I am running into the limit where I did not expect it.
For example if I do a for-each such as the one following but I provide a criteria to filter out the records:
for each rec in formtable  [field == "somevalue"]
{
do some task
}
When there are 500 records but for only 25 of them the criteria matches does it count 500 tasks here or does it only count 25?

Also is there a way to debug and find out how many statements have been executed in a script?

Greetings,
Rob