demo/kitchen-sink/docs/odin.odin
raw| 1 | package main |
| 2 | |
| 3 | import "core:fmt" |
| 4 | |
| 5 | main :: proc() { |
| 6 | program := "+ + * 😃 - /" |
| 7 | accumulator := 0 |
| 8 | |
| 9 | for token in program { |
| 10 | switch token { |
| 11 | case '+': accumulator += 1 |
| 12 | case '-': accumulator -= 1 |
| 13 | case '*': accumulator *= 2 |
| 14 | case '/': accumulator /= 2 |
| 15 | case '😃': accumulator *= accumulator |
| 16 | case: // Ignore everything else |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | fmt.printf("The program \"%s\" calculates the value %d\n", program, accumulator) |
| 21 | } |