CPU 100% during a for loop

Hello ,
i wrote this script to add target address of simple queues that have total bytes greater than 50000 to a firewall address list,
but during performing the script my cpu usage stands at 100% for about 3 minutes !!!
p.s : im using rb750G as my router .

does anyone have better idea to get handle this ?
/queue simple
:for i from=1 to=254 do={
:if ([get [find target-addresses=“192.168.7.$i/32”] total-bytes] > 50000) do={
/ ip firewall address-list add address=“192.168.7.$i” list=No_internet
}
}

Fixed logical problem.

Your version have target-addresses instead of target!!!

upgraded my ROS to 6.10 just now …
its getting an error that says : no such item
i think its because the target must be specified with the subnet (here for example 192.168.7.2/32) and “:toip” wont translate ip in that structure.
any solutions ?

Ok, I rewrite from 0 with more logical order:
:foreach queueTest in=[ /queue simple find where total-bytes > 50000 ] do={
:if ( [/queue simple get $queueTest target] in 192.168.7.0/24) do={
/ip firewall address-list add address=[/queue simple get $queueTest target] list=No_internet;
}
};

the if statement still cannot be used because it returns false for every single ip so i removed it from script and now it works greate :wink:
but would you please explain me why there is this much difference in performance between the first script i used and this one ?
Thanks,

The problem is $i inside " " in: “192.168.7.$i/32”
The correct method to join to obtain a string is: “192.168.7.”.$i.“/32”
and must be used “:toip” to convert a string to ip variable.