Your first Emma program Functions and control flow
Loops, conditionals, assignments and functions: everything you need to write a first Emma program.
Functions and control flow
Emma reads the way you would expect. Here is a function that clamps a value, and one that sums a list with it.
1 2 3 4 5 6 7 8 9 10 11 12 13
func clamp(value: Float, min: Float, max: Float) -> Float { if value < min { return min } if value > max { return max } return value } func total(values: Float[]) -> Float { var sum = 0.0 for value in values { sum = sum + clamp(value, 0.0, 1.0) } return sum }