Perulangan While
Perulangan while juga memiliki empat variasi:
i = 10while i > 0 print i i -= 1
while running == true do my_function!i = 10while i > 0 print i i -= 1
while running == true do my_function!i = 10until i == 0 print i i -= 1
until running == false do my_function!i = 10until i == 0 print i i -= 1until running == false do my_function!Seperti loop for, loop while juga bisa digunakan sebagai ekspresi. Ekspresi while dan until mendukung break dengan banyak nilai.
value, doubled = while true n = get_next! break n, n * 2 if n > 10value, doubled = while true n = get_next! break n, n * 2 if n > 10Selain itu, agar sebuah fungsi mengembalikan nilai akumulasi dari loop while, pernyataannya harus di-return secara eksplisit.
Repeat Loop
Section titled “Repeat Loop”Loop repeat berasal dari Lua:
i = 10repeat print i i -= 1until i == 0i = 10repeat print i i -= 1until i == 0Ekspresi repeat juga mendukung break dengan banyak nilai:
i = 1value, scaled = repeat break i, i * 100 if i > 3 i += 1until falsei = 1value, scaled = repeat break i, i * 100 if i > 3 i += 1until false