Language
Control Flow
Learn about conditionals and loops in Kronos
Control Flow
Kronos provides natural language keywords for control flow statements.
Conditional Statements
If Statements
set age to 18
if age is greater than or equal 18:
print "You are an adult"If-Else
set temperature to 25
if temperature is greater than 20:
print "It's warm"
else:
print "It's cold"If-Else-If
set score to 85
if score is greater than 90:
print "Grade: A"
else if score is greater than 80:
print "Grade: B"
else if score is greater than 70:
print "Grade: C"
else:
print "Grade: D or F"Loops
For Loops
Iterate over a range:
for i in range 1 to 10:
print iIterate over a list:
set fruits to list "apple", "banana", "cherry"
for fruit in fruits:
print fruitWhile Loops
let counter to 5
while counter is greater than 0:
print counter
let counter to counter minus 1Break and Continue
Use break to exit a loop early:
for i in range 1 to 10:
if i is equal 5:
break
print i
# Prints: 1, 2, 3, 4Use continue to skip to the next iteration:
for i in range 1 to 10:
if i mod 2 is equal 0:
continue
print i
# Prints: 1, 3, 5, 7, 9Note: break and continue can only be used inside loops.
Nested Control Flow
You can nest conditionals and loops:
for i in range 1 to 5:
if i mod 2 is equal 0:
print f"{i} is even"
else:
print f"{i} is odd"Examples
Finding Maximum Value
set numbers to list 3, 7, 2, 9, 1, 5
let max to numbers at 0
for num in numbers:
if num is greater than max:
let max to num
print f"Maximum: {max}"FizzBuzz
for i in range 1 to 20:
if i mod 15 is equal 0:
print "FizzBuzz"
else if i mod 3 is equal 0:
print "Fizz"
else if i mod 5 is equal 0:
print "Buzz"
else:
print i