+ 2
I am having trouble with the syntax in the recursion example shown. I don't know what the "?" or the number "1" indicates?
n == 0 ? | 1 ... or something like this in their example the example was in shorthand and is a bit difficult to translate as I am trying to see how to calculate the expected results from a recursive expression
3 Respostas
+ 8
It's just a different synthax to write an if/else statement.
a = (n == 0 ? 0 : 1)
is equivalent to
if n == 0 {
a = 0
} else {
a = 1
}
+ 2
Thank you - I was going crazy looking for an example of this 'shorthand' somewhere - thanks again
+ 1
It's the ternary operator taking 3 operands