Kronos
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"

Pattern Matching

Use match when you want to branch on one value against a sequence of cases:

let status to "ready"

match status:
    case "ready":
        print "Start work"
    case "waiting":
        print "Hold"
    default:
        print "Unknown status"

Kronos evaluates the match value once, checks case branches from top to bottom, and runs the first matching block. default is optional, but it must be the last branch if you include it.

Loops

For Loops

Iterate over a range:

for i in range 1 to 10:
    print i

Iterate over a list:

set fruits to list "apple", "banana", "cherry"

for fruit in fruits:
    print fruit

While Loops

let counter to 5

while counter is greater than 0:
    print counter
    let counter to counter minus 1

Break 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, 4

Use 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, 9

Note: 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"

Debug Statements

Use debug when you want temporary runtime visibility while developing:

set user to "Ned"
set score to 87

debug "user:", user
debug "score and pass status:", score, score is greater than or equal 70

debug accepts one or more expressions separated by commas, evaluates them left to right, and emits a single debug output line.

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

On this page