I am trying to figure out what this pseudocode would be in Julia code:
Pseudocode:
for (i = 0; (i < 32) && (array[i] ≠ nil); i += 1) do result := merge(array[i], result) array[i] := nil The multiple conditions seem to trip me up. I don't know how to format it in Julia. If anyone knows how I would appreciate it. I am new to the language.
22 Answers
There are multiple ways to do it in Julia. For example, you can use break statement
for i in 1:32 # in Julia we usually start numbering from 1 array[i] == nothing && break result = merge(array[i], result) array[i] = nothing end or while loop
i = 1 while i <= 32 && array[i] != nothing result = merge(array[i], result) array[i] = nothing i += 1 end You could do the looping and put the conditional inside:
nil = nothing #or any other sentinel value for i in 1:32 #for i in eachindex(array) if array[i] != nil #if cond1 & cond2 & cond3... &condn result = merge(result, array[i]) array[i] = nil end end 1