Lopps in Verilog and VHDL represent replication spacially, which is not the same as a temporal repeatition. Hence, loops when synthsized into logic or elaborated for simulation must have a constant for the number of itterations.
Ask yourself hoow can this circuit be realized if the circuit has to change the amount of logic that exists on the fly?
This is the saame reason you can't use a varable width for a bitslice as it implies dynamically generated logic.
Another observation is you seem to be trying to decode some state variable in an initial block. Initial blocks are only executeed once at time 0. As your state machine can't execute in 0 ns, that if compare will fail and none of the for loop logic will used.
You have to step back and not attempt to implement this as a software program, but think of what hardware logic gates and registers you need.