Search code examples
functionfor-loopozmozart

for loop in mozart/oz doesn't work


I want to have a for loop in my program which is written in mozart-oz. every time I try a for loop, it gives me error. I've checked the syntax and its true but it gives error. here is my code:

OZ:

declare
fun {Test L}
   for E in L do
      {Browse L}
   end
end

declare
L = [1 2 3 4 5]
{Test L}

please help.

thanks


Solution

  • The problem here is the missing return value of Test. If you want to define a "function" which does not return anything, use the prockeyword:

    declare
    proc {Test L}
       for E in L do
          {Browse L}
       end
    end
    
    L = [1 2 3 4 5]
    {Test L}