Question

Just started using Scilab, looks like a lot to learn but I am stuck at very first basic program. I need to display 1 to 10 numbers without using loop. I know that using loop we can use this code to display numbers from 1 to 10:

for i = 1:10
disp(i)
end

But i need to display them without using any loop. In C programming it's a bit easy using recursive function but here i have tried alot and failed. Please can any one help me out via code snippet.

Était-ce utile?

La solution

I think a recursive call is still kind of a loop, but it could be done like this:

function recursivePrint(i, maxNumber)

     if( i <= maxNumber )
         disp(i)
         recursivePrint(i+1, maxNumber)
     end

endfunction

recursivePrint(1, 10);

Usually when people ask to write a function without a loop they mean something like:

disp(1:10) 

Autres conseils

disp(1)
disp(2)
disp(3)
disp(4)
disp(5)
disp(6)
disp(7)
disp(8)
disp(9)
disp(10)

Curious what you tried..

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top