"Range must be bounded by constant expression" - Error from a constraint block

In reply to Tudor Timi:

Brilliant !
It works for me.
But just to cross check my coding, I am trying to print the contents of legal_nexts array.
However I try to print, my simulation is getting stuck.
If I comment out that printing section, simulation proceeds smoothly.

Any idea?