Loops

Baobab has two loops: pour … dans … iterates over an iterable (Python: for … in …), and tantque repeats while a condition stays true (Python: while).

1
2
pour i dans intervalle(3): afficher(i)
0 1 2

intervalle(n) yields 0…n-1; intervalle(a, b) yields a…b-1. Inside a loop, casser exits immediately (Python: break) and continuer skips to the next iteration (continue).

1
2
3
4
n = 0 tantque n < 3: afficher(n) n = n + 1
0 1 2

A pour loop iterates just as well over an intervalle, a list, a string, or a dictionary's keys.