Problem with a variable

Why this code doesn’t work ? I have the error : maxL not defined
"
maxL=0
for j in 1:size(jobs_in_file,1)
if ((ordered_jobs[j].start_time + ordered_jobs[j].proc) > ordered_jobs[j].due)
maxl1 = maxL + 0
maxL = max(ordered_jobs[j].start_time + ordered_jobs[j].proc - ordered_jobs[j].due, maxL)
end
end
"
Thanks for the help!

for introduces a new local scope, see Scope of Variables · The Julia Language. See for loop - Scope of variables in Julia - Stack Overflow for some more discussion and solutions.

See also PSA: how to quote code with backticks

2 Likes

You could wrap the code in a let…end block. This would put maxL in scope.

let
    [your code here]
end
2 Likes