Summary
There is a need to support switch statements in ZkC. This should differ slightly in semantics (i.e. meaning) from switch statements in e.g. C. Specifically, it should not support automatic fall thru semantics. Instead, it should follow go semantics for switch statements (see here).
Example
Here is a proposed example syntax:
pub input data(address:u16) -> (byte:u8)
// prove that two numbers add up to a third.
fn main() {
var val:u8 = data[0]
var res:u8 = data[1]
if example(val) != res {
fail
}
}
fn example2(val:u8) -> (r:u8) {
switch val {
case 0:
r = 0
case 1:
r = 1
case 2,3:
r = 1
default:
r = 2
}
return
}
Note here that case 2,3: illustrates the ability to specify multiple cases together. Furthermore, example is equivalent to the following:
fn example(val:u8) -> (r:u8) {
if val == 0 || val == 1 {
r = 0
} else if val == 2 {
r = 1
} else if val == 3 {
r = 1
} else {
r = 2
}
//
return
}
Some test cases would be:
Summary
There is a need to support
switchstatements in ZkC. This should differ slightly in semantics (i.e. meaning) fromswitchstatements in e.g. C. Specifically, it should not support automatic fall thru semantics. Instead, it should followgosemantics forswitchstatements (see here).Example
Here is a proposed example syntax:
Note here that
case 2,3:illustrates the ability to specify multiple cases together. Furthermore,exampleis equivalent to the following:Some test cases would be: