Spaces:
Sleeping
Sleeping
File size: 379 Bytes
04307b3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // while_loop.cl — Demonstrates the while-loop
//
// Syntax: while CONDITION { body }
// The condition must be a comparison ('>', '<', or '==').
int x;
x = 10;
// Countdown from 10 to 0
while x > 0 {
x = x - 1;
}
// While with a nested if/else inside the body
int n;
n = 16;
while n > 1 {
if n > 8 then {
n = n - 4;
} else {
n = n - 1;
}
}
|