Swazi Loop Controls: simama & endelea
In SwaziLang, you can control the flow inside loops using simama and endelea:
simama— "break": Immediately stops the current loop and continues after it.endelea— "continue": Skips the rest of the current iteration and starts the next loop step.
These work in all loop types:
kwa(for)kwa kila(for-each)wakati(while)fanya-wakati(do-while)
Usage Examples
1. Using endelea (Continue)
Skip specific values or steps in your loop.
swazi
kwa(i=1; i<=5; i++):
kama i == 3:
endelea; // Skip when i is 3
chapisha i
// Prints: 1 2 4 52. Using simama (Break)
Stop the loop entirely when a condition is met.
swazi
kwa(i=1; i<=5; i++):
kama i == 4:
simama; // Stop when i is 4
chapisha i
// Prints: 1 2 33. With kwa kila and Ranges
swazi
kwa kila val, i katika Orodha(10):
kama i > 5:
simama;
chapisha i
// Prints: 0 1 2 3 4 54. While Loops
swazi
data i = 0
wakati i < 5:
i++
kama i == 2:
endelea;
chapisha i
// Prints: 1 3 4 55. Do-While Loops
swazi
data x = 0
fanya {
kama x == 3:
simama;
chapisha x
x++
} wakati x < 5
// Prints: 0 1 2When to Use
endelea: When you want to skip some iterations but keep looping.simama: When you want to exit the loop early.
Both help make your loops more flexible and expressive!
Summary Table
| Keyword | Purpose | Works In |
|---|---|---|
simama | Stops the current loop | kwa, kwa kila, wakati, fanya-wakati |
endelea | Skips to next iteration | kwa, kwa kila, wakati, fanya-wakati |
Tip:
Use these controls to write clear and efficient loops—skip or exit when needed!