title: OCaml task, Contagion, issues with syntax
body: <p>This is the task:</p>
  <blockquote>
  <p>Write a function <code>onstepcontagion : bool array array -&gt; bool array array = &lt;fun&gt;</code> that given a rectangular bool matrix, where true represents an infected square and false represent non-infected square it calculates the next step of infection. Infected squares remain infected indeﬁnitely, non-infected squares become infected if the they are vertically/horizontally adjacent to at least two other infected squares</p>
  </blockquote>
  <p>This is my code so far:</p>
  <pre><code>    let printmat matrix =
        let n = Array.length matrix in
        let n1 = Array.length matrix.(0) in
        for i = 0 to n - 1 do 
          for j = 0 to n1 - 1 do
            if matrix.(i).(j) == true then print_string&quot;1&quot;
            else print_string&quot;0&quot;;
          done; 
          print_string &quot;\n&quot;;
        done;;
        
        let onstepcontagion matrix =
        let n = Array.length matrix in
        let n1 = Array.length matrix.(0) in
        for i = 0 to n - 1 do
          for j = 0 to n1 - 1 do
              let tmp = 0 in
              if (j &lt; n1-2) then
                 let right = if matrix.(i).(j+1) = true then 1 else 0 in
              if (j &gt; 0) then
                  let left = if matrix.(i).(j-1) = true then 1 else 0 in
              if (i &lt; n-2) then
                  let up = if matrix.(i-1).(j) = true then 1 else 0 in
              if (i &gt; 0) then
                  let down = if matrix.(i+1).(j) = true then 1 else 0 in
              let sum = right + left + up + down in
              if sum &gt; 1 then print_string &quot;JTB &quot;
              else print_string &quot;0&quot; 
          done; 
        done;;
  </code></pre>
  <p>I have no errors, but no output when I call the function. I am very confused regarding the syntax and function of OCaml, I am a total beginner and still in learning phase. I wrote my task in C, I was trying to implement a similar solution in ocaml.</p>
  <p>C code:</p>
  <pre><code>
      #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      
      void print_mat (int n, int m, int arr[n][m])
      {
          int i,j;
          for (i = 0; i &lt; n; i++){
              for (j = 0; j &lt; m; j++)
                  printf(&quot;%d &quot;,arr[i][j]);
              printf(&quot;\n&quot;);
          }
          printf(&quot;\n\n&quot;);
      }
      
      
      int main()
      {
          int n, m, i, j, tmp, changes = 1;
          printf(&quot;input Mat len\n&quot;);
          scanf(&quot;%d%d&quot;,&amp;n,&amp;m);
          int arr[n][m];
          int cpy[n][m];
          for (i = 0; i &lt; n; i++)
              for (j = 0; j &lt; m; j++){
              scanf(&quot;%d&quot;,&amp;tmp);
              if (tmp == 0)
                  arr[i][j] = tmp;
              else
                  arr[i][j] = 1;
              }
          while (changes){
              changes = 0;
          for (i = 0; i &lt; n; i++){
              for (j = 0; j &lt; m; j++)
              {
                  tmp = 0;
                  if (arr[i][j] != 1){
                      if (j &lt; m-1)
                          if (arr[i][j+1] == 1)
                              tmp++;
                      if (j &gt; 0)
                          if (arr[i][j-1] == 1)
                              tmp++;
                      if (i &lt; n-1)
                          if (arr[i+1][j] == 1)
                              tmp++;
                      if (i &gt; 0)
                          if (arr[i-1][j] == 1)
                              tmp++;
                      if (tmp &gt; 1){
                          cpy[i][j] = 1;
                          changes = 1;
                      }
                  }
              }
              }
              if (changes == 1){
               for (i = 0; i &lt; n; i++)
                  for (j = 0; j &lt; m; j++)
                  if (arr[i][j] == 1 || cpy[i][j] == 1)
                      arr[i][j] = 1;
                 printf(&quot;\n&quot;);
                 print_mat(n,m, arr);
              }
          }
          return 0;
      }
      //010  100  001  000
  
  </code></pre>
  <p>I would appreciate if someone could give me a hand here. I learn best trough examples, and I am unable to find similar solved tasks to learn from.</p>