How to stop reading at 600 readings

Hi, how do i stop the looping after 600 readings or 60sec?

void loop()
{
  for (int i=0; i<600; i=i+1){
  regAddress();
  //thermocouple();
  //Serial.write(10);
  delay(100);  //It appears that delay is needed in order not to clog the port
}
}

is this correct ?

loop() executes over and over.
Put the for loop in setup() and it will run only once (for 600 iterations).

Alternatively, loop() could look like this.

void loop() { 
   static int i=0;
   if (i < 600)  {
     do_something();
      i++;
   }
}

jremington:
loop() executes over and over.
Put the for loop in setup() and it will run only once (for 600 iterations).

Alternatively, loop() could look like this.

void loop() { 

static int i=0;
  if (i < 600)  {
    do_something();
      i++;
  }
}

Hi Jerminton,

void loop() {
   static int i=0;
   if (i < 600) {
   regAddress(); i++;
   delay(100);
 }
}

I tried using this code but it does not stop at 600 iterations

I tried using this code but it does not stop at 600 iterations

Please provide evidence for this assertion.

Note, the loop will continue looping, but regAddress() won't be called after i=599.

Add a flag:

byte runComplete;
byte i;
void setup(){
// whatever
}
void loop() {
if (runComplete == 0){
  for (i=0; i<600; i=i+1){
     regAddress();
     delay(100);
   }
  runComplete = 1;
  }
//whatever else happens ...
}

jremington:
Please provide evidence for this assertion.

Note, the loop will continue looping, but regAddress() won't be called after i=599.

i am still reading data after 600 iteration

[/quote]

CrossRoads:
Add a flag:

byte runComplete;

byte i;
void setup(){
// whatever
}
void loop() {
if (runComplete == 0){
  for (i=0; i<600; i=i+1){
    regAddress();
    delay(100);
  }
  runComplete = 1;
  }
//whatever else happens ...
}

i tried to looked at the number of iteration it seems that the maximum number of iteration is 255. After that it revert to 0 and repeat the process.

Don't use a byte to store 'i'; it can only hold from 0 to 255 so will never reach 600. Use an int instead.

void loop() {
   static int i=0;
   if (i < 600) {
   regAddress(); i++;
   delay(100);
 }
}

I tried using this code but it does not stop at 600 iterations

Please provide evidence for this assertion.

i am still reading data after 600 iteration

How are you reading the data? What data are you reading? What is the regAddress() function?
You will need to provide more evidence.

The issue has been resolved, thank to everyone!