Hello everyone! First of all, take in count that I’m a spanish speaker (sorry)
I really don’t understand why I must use the word ‘true’ inside the switch. I tried using the ‘score’ variable but it does not work.
if (machineActive) {
switch (**true**) {
Thanks for your responses!
Greetings from Argentina
mikoMK
(Michael Koch)
July 15, 2022, 3:14pm
2
Hi @roque.nicolas.molina
No need to be sorry!
I tried answering in this recent post:
Hi @AnsBdran
It’s an rather unusual method to use the switch statement, but if we think about the basics of switch/case, it hopefully becomes a bit clearer why it works:
For every case its value gets compared to the switch value. If they are the same, the case code gets executed. Let’s assume the score is 42. Most of the case conditions are false (e. g. score >= 20 && score < 40 true && false false). Only one condition is true: score >= 40 && score < 70, because 42 …
Does that make it clearer?
Michael
1 Like
Thank you!
It cleared my doubt.
Really apreciate your contributions!
1 Like