Loops
pe (tien i = 0; i < 3; i++) { … } repeats while counting (for). mentre che (condition) { … } repeats while the condition is true (while); primm fa { … } mentre che (…) runs the block at least once (do…while).
pe ogni (chist è x dint list) walks the items one by one (for…of); pe ogni (chist è key 'ncopp object) walks the keys of an object (for…in).
rompe leaves the loop (break) and salta skips to the next round (continue). An endless loop does not freeze the page: the playground stops it after a few seconds.
pe (tien i = 1; i <= 3; i++) {
stamm a dì("Giro", i)
}
tien caffè = 0
mentre che (caffè < 2) {
caffè++
}
stamm a dì("Caffè:", caffè)
chist è pizze = ["margherita", "marinara", "diavola"]
pe ogni (chist è pizza dint pizze) {
si (pizza == "marinara") {
salta
}
stamm a dì(pizza)
}
chist è prezzi = { margherita: 6, diavola: 8 }
pe ogni (chist è nome 'ncopp prezzi) {
stamm a dì(nome, prezzi[nome])
}
Output
Giro 1
Giro 2
Giro 3
Caffè: 2
margherita
diavola
margherita 6
diavola 8