Not entering Loop

Hello,

So I have been trying to work on this program that simulates the “Simon” color repetition game and I have had some trouble with the code not entering a loop. So what I would like this code to do is turn 4 LED’s on in a random order and to repeat that same order. I have begun with the first turn turning on one of the LEDs 4 times. Then every correct response adds another LED turning on. The colors[100] array contains integers determining which LED should turn on. I have been debugging my code by using the LED with PIN13 and the serial monitor, and I have determined the problem lies in the first loop (I have tried both a for loop and a while loop, but the code isn’t entering either of them. So now the colors array is never initialized.

Thanks for the help!!

void setup() {
  //Lights
  pinMode(2, OUTPUT); //LED1
  pinMode(3, OUTPUT); //LED2
  pinMode(4, OUTPUT); //LED3
  pinMode(5, OUTPUT); //LED4


  //Switches
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);


  int initialize = 1;

}

void loop() {
  //initialize variables and arrays
  int initialize;
  int numberShown = 0;    //number of lights that have shown up
  int numberWanted;   //number of lights that light up for the turn
  int counter = 0;
  int colors[100];


  //initialize color array
  if (initialize == 1)
  {
//----------------------------------------------------------------------------------------------------
//---------------------------------this is the loop it is not entering--------------------------------
//----------------------------------------------------------------------------------------------------
    while (counter < 100)
    {
      colors[counter]= random(2,5) ;
      counter = counter + 1;

    }   
 
    initialize = 0;    //set to zero so array wont initialize again
    counter = 0;    //re-initialize counter for later use
    numberWanted = 4;   //Numbers wanted will increase every loop.  If it was initialized earler, it would have a constant value and the same number of lights would show
  }



  //Display the colors on the LED
  for (numberShown = 0; numberShown < 4; numberShown = numberShown + 1)
  {

    digitalWrite(colors[numberShown], HIGH);
    delay(1000);
    digitalWrite(colors[numberShown], LOW);
    delay(250);
  }

}

Did you mean to declare colors as static? I'm pretty sure you did...

You have to initialize your "initialize" variable in the loop function, or to make it global (visible to all functions).

In the setup function you have this declaration with initialization:

 int initialize = 1;

This declaration is only visible in the setup function, not in the loop function.

In the loop function you have this declaration without initialization:

int initialize;

So, the "initialize" variable has a random value.