Analog input not working with Serial monitor

Hi guys,
I’m having a problem when I try to use the Analog input along with the Serial monitor. I wrote a routine that is supposed to fill a vector with several measures, and then once it is finished, it sends this vector through the serial monitor. The problem is, when I run the software, it seems it runs both loops in parallel, while one loop is collecting the measures, the other loop is printing them, i see that because when i disconnect my sensor, the serial changes its output to zero, when the loop is supposed to print only the measures already recorded. I am sure the routine is not running more than once, since I got a boolean blocking this routine. Plus, it has to be fast, thus I can’t put a delay within the AnalogRead’s loop, and i’ve set the ADC clock to operate to 1MHz. Here is a piece of my code:

 int i=0;

  if(onetime == false){
  onetime = true;
     for (i = 0 ; i < 1000 ; i++) 
     Ivector[i]= analogRead(Iport) ;
     for (i = 0 ; i < 1000 ; i++){


1000 int(s) is 2000 bytes, how much SRAM do you have?


I am using ArduinoMega, so I got 8KB. Plus, I've tested with a hundred and I still have the same problem.

Show your full code or a representative compilable example.

Hey guys, thanks, I found the mistake when you said to me rewrite the code in a compilable example, it wasn't related to this piece of code, now it's working perfectly!! cheers guys!!!

And the mistake was…?
If someone search and find this thread and realize it is the same problem, it is quite annoying to see you found the problem, but doesn’t share the solution.

Reference page says “The for statement is used to repeat a block of statements enclosed in curly braces.” Was it the mistake?