Skip to content

7. Loops

CoolElectronics edited this page Jul 3, 2022 · 1 revision

There are currently 2 kinds of loops in zsp. the "infinite loop"

loop{
  put "again and"
}

this will keep repeating the code in the loop until it is broken out of
here is an example of breaking out of a loop

counter = 0
loop{
  put counter

  counter = counter + 1
  if counter > 10{
     break
  }
}

there is also the for loop, identical to for loops in c or similar langauges the syntax is for (variable name) (inital value) (condition) (incrementor)

for i 0 i < 100 i = i + 1{
   put i
}
// result: 0 1 2 3 4.... all the way to 99

yes this is super unreadable. honestly i don't care

Clone this wiki locally