Create boolean in for loop

I want to make a binary switch out of a sensor, and in order to do that I turn the variable into a boolean.
However, I want to do this many times.

  long val1 =  cs_4_2.capacitiveSensor(30);
  long val2 =  cs_4_6.capacitiveSensor(30);
  long val3 =  cs_4_8.capacitiveSensor(30);

  boolean boo1;
  boolean boo2;
  boolean boo3;
   if (val1 >= 20) {
    boo1 = true;
  else {
    boo1 = false;
  if (val2 >= 20) {
    boo2 = true;
  else {
    boo2 = false;
  if (val3 >= 20) {
    boo3 = true;
  else {
    boo3 = false;

I basically have to write the same if/else statement over and over again, but with another consecutive number. This is inconvenient as i plan on having many sensors.

Is there any way where i can make a for loop where the number of the sensors can be put behind the name of the boolean? Think: valX to boolX or do I need an array for this?

Thank you for your time and effort! :slight_smile:

Thanks for using code tags! Yes, a for loop and arrays are a fine solution. I think you will need a way to index the sensor objects in that loop (cs_4_2, cs_4_6, etc.). So you need an array of sensor objects, or an array of structs with the objects and also the boolean variables contained in each element.

The advice on how to do that, will come sooner from the OO experts on here than from me. I think I've done it but it would take me too long to dig that up. It's relatively easy.