While loop, variable not defined

Hi, I’m doing the Introduction to Julia course (https://juliaacademy.com/courses/375479/lectures/5816184) and this happens when i run the code for a while loop.

¿Could someone explain this to me and tell me the correct way to do it?

the warning message before the error literally tells you what’s going on, please read it.

In this case, you want to take the global i advise probably

1 Like

Welcome @nicoo-c
You find all you need about this here: Scope of Variables · The Julia Language

3 Likes

Thanks, I understand now.

Solved with:

i = 0

while i < 10
  global i += 1
  println(i)
end
2 Likes