let greeting = Hello greeting ts string print greeting_string World .
From the repository · examples/
Example programs
Real .qc files shipped with Qingchu.
Run any of them with
java -cp out qingchu.Main run examples/<file>.qc.
OutputHello World
let name = Alice name ts string math let age = 16 . let likes_code = true likes_code ts boolean print Hello name_string . print Age: age_number years old . string print You said you like coding: likes_code .
OutputHello Alice
Age: 16 years old
You said you like coding: true
math let age = 20 . math if age > 18 print You are an adult . else print You are a minor .
OutputYou are an adult
math let i = 0 . math when i < 3 print Count: i . math new i = i + 1 . print Done. Loop ran 3 times .
OutputCount: 0
Count: 1
Count: 2
Done. Loop ran 3 times
print Grade Calculator . print Enter scores one at a time. Type 0 to finish. . math let total = 0 . math let count = 0 . ask Enter a score (0 to finish): . response = score score ts number math when score > 0 math new total = total + score . math new count = count + 1 . ask Enter a score (0 to finish): . response = score score ts number math let average = total / count . math print Average: average . math if average > 89 print Letter grade: A . else math if average > 79 print Letter grade: B . else math if average > 69 print Letter grade: C . else math if average > 59 print Letter grade: D . else print Letter grade: F .
SessionEnter a score (0 to finish): 92
Enter a score (0 to finish): 85
Enter a score (0 to finish): 0
Average: 88.5
Letter grade: B
!! --- 1. Comments --- !! !!! This is a multi-line comment it continues here !!! let greeting = Hello greeting ts string print greeting_string . math let price = 10 . math let quantity = 5 . math let total = price * quantity . math print total .
OutputHello
50
let pi = 3.14 pi ts constant number print pi_constant_number . math if age > 18 print You are an adult . else print You are a minor . !! --- 8. When loop --- !! math when i < 3 print Count: i . new i = i + 1 . !! --- 9. Countdown --- !! math when n > 0 print n . new n = n - 1 . print Liftoff .
Output3.14
Count: 0
Count: 1
Count: 2
5 4 3 2 1
Liftoff
!! --- 10. Define a function --- !! define double(x) as x * 2 x ts number double ts number !! --- 11. Define with block body --- !! define square(x) as x ts number square ts number let result = x_number * x_number result ts number calculate result_number . !! --- 12. Ask for input --- !! ask What is your name? . response = name name ts string string print Nice to meet you, name . print All tests complete .
SessionWhat is your name? Ada
Nice to meet you, Ada
All tests complete
Try it yourself.
Clone the repo, compile once, and run any .qc file — or play in the REPL.