hello everyone.
is there a trick or a solution to interact with all boolean variables in one keyword ?
I hope something like " all.boolean == true" .
I think I already saw something like this but I can’t remember exactly.
do we have a way to do this or is it just a dream ??
Thanks a lot for your help
Fred
I don’t fully understand what you mean, but yeah.
Do you mean to check for multiple booleans and see if they are true?
You can do that by using && simbols. It means AND. So print( 1 < 2 && 4 != 5) would print out “true”
Alternatively you can make a function comparring all of the inputs. (Here is one I wrote (not tested yet, but it should work)
boolean check(boolean desired, boolean... inputs) {
for(int i = 0; i < inputs.length; i++) if(inputs[i] != desired) return false;
return true:
}
1 Like
Hello,
Sorry I just saw your answer, thanks a lot.I will check your ideas.
1 Like
remember
- that
==
is for comparison in if: if(boolMy == true) {...
and
- that = is for assignment:
boolMy = true;
sets boolMy to true
Remark 1
technically, if(boolMy == true)
is not necessary, you can say if(boolMy) { ....
When you have a few booleans you want
if(boolMy1 && boolMy2 && boolMy3 && boolMy4) {....
Remark 2
when you have multiple booleans, maybe have them in an array (which is a list) then you can for loop over them
Chrisir