Matlab control flow commands - examples

Branching Loops
  if (k == 0)
    ...
  else
    ...
  end  
  while (a > 3) && (b ~= 3)
    ...
  end  
  if (a > 0) || (a < 6)
    ...
  end  
  for k = [1 3 5 -2]
    ...
  end  
  if (q >= 3)
    ...
  elseif (q  >= 1)
    ...
  elseif (q  >= 0)
    ...
  else
    ...
  end  
  for k = 1 : n
    ...
  end  

  for k = n : -2 : 1
    ...
  end  

Last updated 15. september 2021