dimanche 7 juillet 2019

While loop in Julia

The following code, while admittedly simple, is confusing. Why is the second increment necessary and doesn't the continue statement keep the flow within the first if conditional? At what point is the second if conditional checked?

i = 1

while i < 20
  if (i % 2) == 0
    println(i)
    global i += 1
    continue
  end

  global i += 1
  if i >= 10
    break
  end
end

I have started teaching myself Julia and the aforementioned syntax looks rather alien.

Thank you.

Aucun commentaire:

Enregistrer un commentaire