I would like to write a function in a .jl file, that can recursively produce polynomials for me. However I got the following error message: invalid iteration specification.
> function P(n)
Pn(x)=1 ##if n==0 Pn(x)=1
global i=0 ##declare i for the for loop
seged(x)=x ##declare the function for the for loop
for global i in 1:n-1
seged(x)=(((2*i+1)*x*Pn(x)-(i)*Pn_1(x))/(i+1)) ##the formula for the recursive function
Also I have come from Octave and this code run without errors back there.
The error is thrown when the text fails to parse to a valid Julia expression.
julia> :(for global i in iter end)
ERROR: syntax: invalid iteration specification
 top-level scope
It’s also redundant, you already had the global i declaration earlier. A for loop (or let block) header introduces a new local variable into their scope by default, so if you want to reassign a global variable, you could 1) rename the iteration variable e.g. for i2 in 1:n-1 and assign i = i2 in the body, or 2) specify for outer i in 1:n-1 to borrow i from the outer scope.
Mostly unrelated to the error, but expect more syntax and design differences in totally unrelated languages, this isn’t like Octave cloning MATLAB.