3

I can't find a way to emulate an AND statement in a switch statement:

if (angle >= 10 and angle <= 30)
   ;// do smth
else
   ; // this is what I want

Until now, I just nested two if statements, but now I want to introduce an else case, but I don't want to duplicate the statements in the else condition two times (one in the first if, the second one in the nested one).

Is there a better way?

  • 2
    Hi SchoolGuy and welcome to Bricks! Which language are you using to program your EV3? (Hopefully you can edit your question to include that). – Zhaph - Ben Duguid Nov 15 '17 at 10:16
2

You can put all of the logic outside of the switch block and use the "Logic" input of the switch block. You can do exactly what you have described in pseudo code since there are "less than"/"greater than" blocks and an "and" block.

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.