Loops¶
Ooga Booga provides two loop constructs: UGGA WHILE for condition-driven loops, and UGGA DO for infinite loops. Both are closed with UGHA.
UGGA WHILE — while loop¶
Executes the body repeatedly as long as the condition is truthy.
Output:
The condition is checked before each iteration. If it is falsy on the first check, the body never executes.
UGGA DO — infinite loop¶
Runs the body forever until a STOP statement is reached.
Use UGGA DO when the exit condition is naturally in the middle or end of the body.
STOP — break¶
STOP immediately exits the innermost enclosing loop. Using STOP outside any loop is a semantic error.
SKIP — continue¶
SKIP skips the rest of the current loop body and proceeds to the next iteration.
OOF Print only odd numbers 1–9
OOGA i BE 0
UGGA WHILE i SMALLR 10
i GETS i PLUS 1
IFF i MOD 2 IS 0
SKIP
UGHA
SAY i
UGHA
Output:
Nested loops¶
Each loop has its own UGHA. STOP and SKIP only affect the innermost enclosing loop.
OOGA row BE 1
UGGA WHILE row SMALLR IS 3
OOGA col BE 1
UGGA WHILE col SMALLR IS 3
SAY WORDY(row) PLUS "," PLUS WORDY(col)
col GETS col PLUS 1
UGHA
row GETS row PLUS 1
UGHA
Output:
Tips¶
- Always update the loop variable inside the body or you will create an infinite loop.
- Use
UGGA DOwithSTOPfor loops where the exit condition depends on user input or complex mid-body logic. - The Fibonacci example in the Examples page shows a practical while loop.