@fati1988 As I said earlier I'd do four nested loops with a complicated if statement. This is not the most efficient, but is probably the most readable. But there will be 256 cases in the if statement (only one in the sample below) so really it is better to work out the pattern - perhaps from knowing the derivation which led to it.
for l from 1 to N_x do
for p from 1 to N_y do
for l_prim from 1 to N_x do
for p_prim from 1 to N_y do
if l::even and p::odd and l_prim::odd and p_prim::even then
H[i,j]:=KroneckerDelta[l, l_prim]*KroneckerDelta[p, p_prim+1]
+KroneckerDelta[l, l_prim-1]*KroneckerDelta[p, p_prim-1]