Adding two numbers
let a = 6let b = 4print(a + b)
One row per step: a new value, a check (yes or no), or a print.
| Step | Line | a | b | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
Heads up: this browser isn't saving anything for this site, so progress and settings reset when you leave the page. Everything still works while you're here.
Before computers, people ran programs on paper. Pick a program, print its page, and be the machine: go line by line and fill in one row for every step the machine takes: a new value in a box, a check (yes or no), or a print. Some rows are only a check, so some boxes stay empty. When you are done, check your table on the live machine.
let a = 6let b = 4print(a + b)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | a | b | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
var score = 3score = score + 5score = score * 2print(score)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | score | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 |
Check it on the live machine: sparkanvil.org/play/traceforge
let name = "Ada"let age = 9print("\(name) is \(age)")One row per step: a new value, a check (yes or no), or a print.
| Step | Line | name | age | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
let total = 7let friends = 2print(total / friends)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | total | friends | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
let sunny = truelet warm = falseprint(sunny && warm)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | sunny | warm | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
let door = falselet open = !doorprint(open)print(door)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | door | open | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 |
Check it on the live machine: sparkanvil.org/play/traceforge
let word = "robot"print(word.count)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | word | Prints |
|---|---|---|---|
| 1 | |||
| 2 |
Check it on the live machine: sparkanvil.org/play/traceforge
let cookies = 17let perBag = 5print(cookies % perBag)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | cookies | perBag | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
let first = "Sun"let second = "flower"print(first + second)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | first | second | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
var a = 2var b = 5a = bb = aprint(a)print(b)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | a | b | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 |
Check it on the live machine: sparkanvil.org/play/traceforge
let total = 7.0let friends = 2.0print(total / friends)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | total | friends | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
let x = 4print(x)let y = x + 1print(y)print(x)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | x | y | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 |
Check it on the live machine: sparkanvil.org/play/traceforge
let n = 8if n % 2 == 0 { print("even")} else { print("odd")}One row per step: a new value, a check (yes or no), or a print.
| Step | Line | n | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
for i in 1..<4 { print(i)}One row per step: a new value, a check (yes or no), or a print.
| Step | Line | i | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 |
Check it on the live machine: sparkanvil.org/play/traceforge
var sum = 0for i in 1...3 { sum = sum + i}print(sum)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | sum | i | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 |
Check it on the live machine: sparkanvil.org/play/traceforge
let pets = ["cat", "dog", "fish"]print(pets.count)print(pets[0])One row per step: a new value, a check (yes or no), or a print.
| Step | Line | pets | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
let t = 15if t > 20 { print("hot")} else if t > 10 { print("mild")} else { print("cold")}One row per step: a new value, a check (yes or no), or a print.
| Step | Line | t | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 |
Check it on the live machine: sparkanvil.org/play/traceforge
let words = ["red", "fox", "ran"]for w in words { print(w.count)}One row per step: a new value, a check (yes or no), or a print.
| Step | Line | words | w | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 |
Check it on the live machine: sparkanvil.org/play/traceforge
var bag: [String] = []bag.append("pen")bag.append("map")print(bag.count)print(bag[1])One row per step: a new value, a check (yes or no), or a print.
| Step | Line | bag | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 |
Check it on the live machine: sparkanvil.org/play/traceforge
var scores = [4, 7, 2]scores[1] = 9print(scores)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | scores | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
var evens = 0for n in 1...6 { if n % 2 == 0 { evens = evens + 1 }}print(evens)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | evens | n | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 | ||||
| 10 | ||||
| 11 | ||||
| 12 | ||||
| 13 | ||||
| 14 | ||||
| 15 | ||||
| 16 | ||||
| 17 | ||||
| 18 |
Check it on the live machine: sparkanvil.org/play/traceforge
var s = "go"for i in 1...3 { s = s + "!"}print(s)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | s | i | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 |
Check it on the live machine: sparkanvil.org/play/traceforge
let age = 10let withAdult = trueif age >= 12 || withAdult { print("ride")} else { print("wait")}One row per step: a new value, a check (yes or no), or a print.
| Step | Line | age | withAdult | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 |
Check it on the live machine: sparkanvil.org/play/traceforge
let n = 2switch n {case 1: print("one")case 2, 3: print("few")default: print("many")}One row per step: a new value, a check (yes or no), or a print.
| Step | Line | n | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
var n = 10while n > 0 { n = n - 3}print(n)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | n | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 | |||
| 11 |
Check it on the live machine: sparkanvil.org/play/traceforge
var total = 0for i in 0..<5 { total = total + i}print(total)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | total | i | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 | ||||
| 10 | ||||
| 11 | ||||
| 12 | ||||
| 13 |
Check it on the live machine: sparkanvil.org/play/traceforge
func triple(x: Int) -> Int { return x * 3}print(triple(x: 4) + 1)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | triple: x | triple returns | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 |
Check it on the live machine: sparkanvil.org/play/traceforge
for a in 1...2 { for b in 1...2 { print("\(a)\(b)") }}One row per step: a new value, a check (yes or no), or a print.
| Step | Line | a | b | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 | ||||
| 10 | ||||
| 11 | ||||
| 12 | ||||
| 13 |
Check it on the live machine: sparkanvil.org/play/traceforge
let nums = [3, 1, 4]var best = nums[0]for n in nums { if n > best { best = n }}print(best)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | nums | best | n | Prints |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 | |||||
| 7 | |||||
| 8 | |||||
| 9 | |||||
| 10 | |||||
| 11 |
Check it on the live machine: sparkanvil.org/play/traceforge
var n = 1var steps = 0while n < 20 { n = n * 2 steps = steps + 1}print(steps)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | n | steps | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 | ||||
| 10 | ||||
| 11 | ||||
| 12 | ||||
| 13 | ||||
| 14 | ||||
| 15 | ||||
| 16 | ||||
| 17 | ||||
| 18 | ||||
| 19 |
Check it on the live machine: sparkanvil.org/play/traceforge
func double(x: Int) -> Int { return x * 2}func addOne(x: Int) -> Int { return x + 1}print(addOne(x: double(x: 5)))One row per step: a new value, a check (yes or no), or a print.
| Step | Line | double: x | double returns | addOne: x | addOne returns | Prints |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | ||||||
| 3 | ||||||
| 4 | ||||||
| 5 | ||||||
| 6 | ||||||
| 7 |
Check it on the live machine: sparkanvil.org/play/traceforge
let x = 1func bump(x: Int) -> Int { return x + 10}print(bump(x: 5))print(x)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | x | bump: x | bump returns | Prints |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 |
Check it on the live machine: sparkanvil.org/play/traceforge
func countdown(n: Int) { if n == 0 { print("Go!") return } print(n) countdown(n: n - 1)}countdown(n: 3)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | countdown: n | countdown #2: n | countdown #3: n | countdown #4: n | Prints |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | ||||||
| 3 | ||||||
| 4 | ||||||
| 5 | ||||||
| 6 | ||||||
| 7 | ||||||
| 8 | ||||||
| 9 | ||||||
| 10 | ||||||
| 11 | ||||||
| 12 | ||||||
| 13 | ||||||
| 14 | ||||||
| 15 | ||||||
| 16 | ||||||
| 17 | ||||||
| 18 | ||||||
| 19 | ||||||
| 20 | ||||||
| 21 |
Check it on the live machine: sparkanvil.org/play/traceforge
func fact(n: Int) -> Int { if n <= 1 { return 1 } return n * fact(n: n - 1)}print(fact(n: 4))One row per step: a new value, a check (yes or no), or a print.
| Step | Line | fact: n | fact #2: n | fact #3: n | fact #4: n | fact returns | Prints |
|---|---|---|---|---|---|---|---|
| 1 | |||||||
| 2 | |||||||
| 3 | |||||||
| 4 | |||||||
| 5 | |||||||
| 6 | |||||||
| 7 | |||||||
| 8 | |||||||
| 9 | |||||||
| 10 | |||||||
| 11 | |||||||
| 12 | |||||||
| 13 | |||||||
| 14 | |||||||
| 15 | |||||||
| 16 | |||||||
| 17 |
Check it on the live machine: sparkanvil.org/play/traceforge
var line = ""for i in 1...4 { if i % 2 == 0 { line = line + "x" } else { line = line + "o" }}print(line)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | line | i | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 | ||||
| 10 | ||||
| 11 | ||||
| 12 | ||||
| 13 | ||||
| 14 | ||||
| 15 |
Check it on the live machine: sparkanvil.org/play/traceforge
var a = 0var b = 10while a < b { a = a + 2 b = b - 1}print(a)print(b)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | a | b | Prints |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 | ||||
| 7 | ||||
| 8 | ||||
| 9 | ||||
| 10 | ||||
| 11 | ||||
| 12 | ||||
| 13 | ||||
| 14 | ||||
| 15 | ||||
| 16 | ||||
| 17 |
Check it on the live machine: sparkanvil.org/play/traceforge
let nums = [1, 2, 3]var out: [Int] = []var i = nums.count - 1while i >= 0 { out.append(nums[i]) i = i - 1}print(out)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | nums | out | i | Prints |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 | |||||
| 7 | |||||
| 8 | |||||
| 9 | |||||
| 10 | |||||
| 11 | |||||
| 12 | |||||
| 13 | |||||
| 14 |
Check it on the live machine: sparkanvil.org/play/traceforge
func square(n: Int) -> Int { return n * n}var total = 0for i in 1...3 { total = total + square(n: i)}print(total)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | total | i | square: n | square returns | Prints |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | ||||||
| 3 | ||||||
| 4 | ||||||
| 5 | ||||||
| 6 | ||||||
| 7 | ||||||
| 8 | ||||||
| 9 | ||||||
| 10 | ||||||
| 11 | ||||||
| 12 | ||||||
| 13 | ||||||
| 14 | ||||||
| 15 | ||||||
| 16 | ||||||
| 17 | ||||||
| 18 |
Check it on the live machine: sparkanvil.org/play/traceforge
struct Jar { var count: Int}var jar = Jar(count: 2)jar.count = jar.count * 3print(jar.count)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | jar | Prints |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 |
Check it on the live machine: sparkanvil.org/play/traceforge
let rolls = [4, 6, 2, 6, 5]var total = 0var sixes = 0for r in rolls { total = total + r if r == 6 { sixes = sixes + 1 }}let average = total / rolls.countif sixes >= 2 { print("lucky")} else { print("plain")}print(average)One row per step: a new value, a check (yes or no), or a print.
| Step | Line | rolls | total | sixes | r | average | Prints |
|---|---|---|---|---|---|---|---|
| 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 |
Check it on the live machine: sparkanvil.org/play/traceforge
Make reading comfier. Saved on this device only — nothing leaves your device.
Same ideas with a younger band's look: bigger type and buttons, a rounder font, slower motion. For any child who wants it.
Auto picks for this device. Lighter uses smaller downloads. Nothing is turned off.