void writereg() {
      digitalWrite(latchPin, LOW);
      for (int i = 7; i >= 0; i--) {
        digitalWrite(clockPin, LOW);
        Serial.print("wswitch&&&&&&");
        Serial.print(i);
        Serial.print("----------------------");
        digitalWrite(dataPin, switches[i].stat);
        Serial.println(switches[i].stat);
        digitalWrite(clockPin, HIGH);
      }
      digitalWrite(latchPin, HIGH);
      touched = false;
    }

I don't understand what's wrong with what I'm doing here, but this for loop runs into an almost infinite loop and prints crazily. I'm a newbie to electronics and Arduino and I don't understand what's wrong here. Please help.

[![enter image description here][1]][1]


  [1]: https://i.sstatic.net/v1kOF.png