Foreach embedded question

I updated the original code and I have another question here. what I tried is to remove the elements which is both existed in arr_a and arr_b. But I hit below error… not sure how to fix it.

Error-[IUCV] Invalid use of ‘const’


foreach (arr_a[i]) begin
    foreach(arr_b[j]) begin
        if(arr_a[i] != arr_b[j]) begin
            ...
        end
        else begin
            arr_a.delete(i);
            arr_b.delete(j);
            i--;
            break;
        end
    end
end

In reply to zz8318:

Have you tried it? Is it not working the way you were expecting?

In reply to zz8318:

both the loops are logically same.
The first one always iterates over all the N(size) elements.
In the second one you have control to choose.

In reply to dave_59:

I tried lots of times but it happened to me that it’s different behavior sometimes today. But it’s strange to me that I can’t reproduce it…anyway, I will use the first code in my proj. Thank you.

In reply to yourcheers:

I updated my question and code. Could you please help ? Thank you

In reply to zz8318:

It would really help to show the exact error message pointing to the exact line having the problem. There is no ‘const’ anywhere in the code you have shown. Also, show us the declaration of arr_a and arr_b. I’m assuming they are queues. You cannot modify the size of an array while you are iterating its elements with a foreach loop. The inner foreach is OK because you are breaking out of it, but not the outer.

In reply to dave_59:

got it . Thank you. I’d like to use for instead of foreach.