A neater way of doing this?
-
I have this line
If (ti[0] == 3) and (ti[1] == 3) and (ti[2] == 3) and (ti[3] == 3) and (ti[4] == 3) and (ti[5] == 3) and (ti[6] == 3) and (ti[7] == 3) and (ti[8] == 3) and (ti[9] == 3)
I wish to find a much neater/shorter way of doing it, what do you suggest?
(I only wish something to trigger if all 10 of ti[0-9] are equal to 3. not one or two, but all of them) -
allTrue = true for i = 0 to 10 loop if ti[i] != 3 then allTrue = false break endif repeat if allTrue then //Do what you gotta do
-
Had something similar to what @Jaywalker posted, but mine went through all of them rather than breaking the moment it found something not true. If this is something you plan to do for multiple different instances, you could convert it to a function and just call the function each time instead
function isAllEqual( arr, tst ) ret = true for i = 0 to len( myarray ) loop if( arr[ i ] != tst ) then ret = false break endIf repeat return ret if ( isAllEqual( ti , 3 ) ) then // doot doot doot else // nah nah nah endIf
-
Thank you! it works.
-
Remember that those kinds or ripetitve checks in which for example just one index changes beetween each condition can be always be done using a for cycle
-
On line 4, i read != what is the difference between == and !=
I am just at the beginning of reading the help section
Thanks
-
@donaldp said in A neater way of doing this?:
On line 4, i read != what is the difference between == and !=
I am just at the beginning of reading the help section
Thanks
== means "is equal to"
!= means "is not equal to" -
@Discostew thanks!