NEWTON
Asked
4 months ago
28
views
1
Hi, I'm trying to solve a Playground exercise on the Cairo website named "Conditionals". I don't know how to make OR operator in Cairo. I tried something like that:
func abs_eq(x: felt, y: felt) -> (bit: felt) {
if (x == -y) or (x == y) {
return (bit=1);
} else {
return (bit=0);
}
}
but it gives me an error
Error: code:12:18: Unexpected token Token('IDENTIFIER', 'or'). Expected: "{". if (x == -y) or (x == y) {
How can I solve it?
Hypobrai
asked
4 months ago
0
I think in this exercise they want you to know about if .. else statement. Try this:
func abs_eq(x: felt, y: felt) -> (bit: felt) {
if (x==y) {
return (bit=1);
}
if (x == -y) {
return (bit=1);
} else {
return (bit=0);
}
}
answered
4 months ago
How to make conditional expressions if..then..else in Cairo lang?
What is the difference between tempvar/let in Cairo Lang? How to use allow_locals and local?
Does Cairo Lang have any logic operators?
What does it mean to declare a 'local' variable inside a 'let'?
Cairo Lang / StarkNet: What are Revoked references? What is alloc_locals?
How to write "and" conditional logic in Cairo?
How to use get_fp_and_pc in Cairo Lang?
How can I verify a contract on starkscan or voyager after deploying the contract
Cairo: let vs tempvar what is the difference?
How can I define two functions with the same name but not the same arguments?
Why should I run a Pathfinder node?
ApeWorX: Why are the cairo and starknet plugins not installing properly?
Error when deploying Cairo: [WARNING] alpha-goerli is a legacy network name parameter and it won't be supported in future versions
How to make conditional expressions if..then..else in Cairo lang?