I have function update2
which returns the values of status, nChange
. However, I need to build function update1
which update status, nChange
without returning their values (in-place mutation) but it seems not correct process. How can I implement that correctly?
using SparseArrays, LinearAlgebra
function update1(status, nChange, check)
if check == 1
status = true;
nChange += 1;
end
end
function update2(status, nChange, check)
if check == 1
status = true;
nChange += 1;
end
status, nChange;
end
function run1()
status = false;
nChange = 0;
check = 1;
update1(status, nChange, check)
status, nChange;
end
function run2()
status = false;
nChange = 0;
check = 1;
status, nChange = update2(status, nChange, check)
status, nChange;
end
status1, nChange1 = run1()
status2, nChange2 = run2()
julia> status1
false
julia> nChange1
0
julia> status2
true
julia> nChange2
1