title: How do I use this variable in if statement in a loop (scope)
body: <p>I'm programming something with an Arduino, which I believe uses C as the base language.  I have this loop:</p>
  
  <pre><code>int i = 0;
  
  void loop()
  {
      //Set The output pin to the MIDI note number - 60.
      int pinNumber = noteNumber - 60;
  
      if (midiMessage == 144) {
          if (velocity == Triggered) {
              registerWrite(pinNumber, HIGH);
              i = pinNumber;
          }
      }
  
      if (midiMessage == 128) {
          if ((i % 8) == (pinNumber % 8)) {
              if (velocity == Stopped) {
                  registerWrite(pinNumber, LOW);
              }
          }
      }
  }
  </code></pre>
  
  <p>I know the above code doesn't work right, but what I'm trying to do is assign the <code>i</code> variable if the first condition is met <code>if (velocity == Triggered)</code>, and then be able to use it when the <code>midiMessage == 128</code> condition is met.</p>