I’m trying to write a while loop that tests whether an input is valid or not and it keeps asking if the user insists on the wrong input. If it is a valid one, the program just goes on. This is where i’m at.
while true
try
selected_row = readline()
selected_row = parse(Int8, selected_row)
break
catch e
if isa(e, LoadError)
@warn "type a valid number between [1,8]"
elseif isa(e, ArgumentError)
@warn "type a valid number between [1,8]"
end
end
end
println("you chose (C|R) ($selected_row)")
The problem is that when the input is correct I get an error.
LoadError: UndefVarError: selected_row not defined