Suppose I have the following code which has two nested while loops.
struct Parameters
maxIter1::Float64
maxIter2::Float64
tolerance1::Float64
tolerance2::Float64
end
mutable struct Guess
x1::Float64
x2::Float64
end
function solveModel(par::Parameters,initGuess::Guess)
iterate1 = 0
error1 = 0
guess = initGuess
while (par.iterate1 < par.maxIter1 && error1 > par.tolerance1)
iterate1 += 1
iterate2 = 0
error2 = 0
guess.x2 = initGuess.x2
while (iterate2 < par.maxIter2 && error2 > par.tolerance2)
iterate2 += 1
z2 = solveInnerProblem(par,guess)
newGuess = update2(par,guess,z2)
error2 = computeError2(newGuess,guess)
guess = newGuess
end
guess = newGuess
end
end
I get an error message,
Note: the reference to the line number is erroenous - line 294 of my code contains no mention whatsoever of newGuess.
The error message goes away if I comment out the line
guess = newGuess
In the outer loop (last line before the final two end
lines in the code snippet). I'm quite confused as to why this is happening. The variable newGuess
is clearly defined, but Julia says it is not defined...