I am pretty new to *Mathematica*. I need to create 2d array dynamicly. I got some code in C++(Qt) and it looks like this: 

```cpp
void Wave::getMatrix(int M, int N)
{
    int k = -N;
    while(k < N+1){
        QVector<tsk_type> temp_vec;

        for(int i = -N; i < N+1; i++){
            tsk_type temp_sum0;

            for(int ii = -M; ii < M+1; ii++ ){
                temp_sum0 += (getI(i-ii, b)/getY(ii)) * getJ(ii-k,b1,b2);
                        }
            temp_vec[temp_vec.size()-1] = temp_sum0;

            if (k == i)
                temp_vec[temp_vec.size()-1] -= l;

                }

        temp_vec.push_back(getD(S)*getI(S-k, b));
        main_array.push_back(temp_vec);
        k++;
    }

}

```

/
In *Mathematica*, I have already written all the functions that I need to make some linear equation system matrix which I can solve. So I use 'em to get 'list' of 'lists'.

When I run this code it's like executing something but outputs nothing. No even errors. 
Whats wrong? And how properly I should translate it? also, I assume that there are problem with 'List[]' and 'List[[]]' variables, so how shold I properly declare dynamic lists? 

Here is the formula 

![enter image description here](https://i.stack.imgur.com/D9PEo.png)

Heres how I translated the code. 

```
(*all globlas definiton is somewhere here*)

 k = -Nm;

        mainmatrix = List[[]];
        While[k < Nm + 1,
                    rowvalues = List[];
                    For[i = -Nm, i < Nm + 1, i++,

                           tempsum;

                           For[j = -M, j < M + 1, j++,    
                                      tempsum = tempsum +  (getI[i - j, a, b]/getGamma[j])                  * getJ[j - k, a1, b1, a2, b]
                           ]

                           AppendTo[rowvalues, tempsum];    

                           If[k == i, AppendTo[rowvalues, -l], 0]
                       ];

                       AppendTo[rowvalues, getD[S]*getI[S - k, a, b]];
                   AppendTo[mainmatrix, rowvalues];

         k++]

```

**UPD**:
all functions and data

```
Clear[k, a, b, a1, b1, a2, b2, angle, rho, omega, lambda, u];
(*constants*)  
rho = 1800; angle = 0.5; lambda = 3 * 10^9; omega = 1.5 * 10^6; u = 
 2*10^9;
BS = 1; DS = 1; T = 0.01; l = 0.01; S = 0;
a = 0.002; b = 0.008; a1 = 0.0; b1 = 0.002; a2 = 0.008; b2 = 1.0; M = 
7; Nm = 7;

getI[k_ , a_, b_] = Integrate[E^(I ((2 Pi)/l) k t), {t, a, b}]

getJ[k_ , a1_, b1_, a2_, b2_] = getI[k, a1, b1] + getI[k, a2, b2]

getL[n_] = angle + (2 Pi n/l); 

getK[j_] = If[j == 1, 
  answer = Sqrt[(rho*omega^2)/(lambda + 2*u)], 
  answer = Sqrt[(rho*omega^2)/(u)]
  ]; answer

getBeta[j_, n_] = If[(getL[n] > getK[j]), 
  beta = 0 + i*(getL[n]* getL[n]  * getK[j]*getK[j]),
  beta =  (getL[n]* getL[n]  * getK[j]*getK[j]) + i*0]; beta

getGamma[n_] = (((getL[n]*getL[n])/(getBeta[1, n])) + getBeta[2, n]);

getD[s_] = ((2 getL[s] * BS * getBeta[1, s] + DS) / (getL[s] * getL[s] 
            + getBeta[1, s]*getBeta[2, s] ));

```