Error Message within a void / for loop: was not declared in this scope

Hi I am currently trying to build code for a PCR machine, but having trouble with one portion of it. I wasn't able to attach the ENTIRE code because of limit on characters, but the part I am having trouble with is in the void runPCR() {
for (; cycles < NUM_CYCLES; cycles++) {
CURRENT_CYCLE = cycles;
...

It continues to tell me that 'cycles' was not declared in the scope...

Thank you ahead of time for any information.

/* Execute the desired number of PCR cycles.
*/
void runPCR() {
  for (; cycles < NUM_CYCLES; cycles++) {
    CURRENT_CYCLE = cycles;
    unsigned long cycleStartTime = millis();
    Serial.print("///CYCLE  ");
    Serial.print(cycles);

    time = millis();
    Serial.println("HEATING UP");
    CURRENT_PHASE = 'H';
    if (!heatUp(DENATURE_TEMP)) {
      // if unable to heat up, stop
      Serial.println("Unable to heat up... something is wrong :(");
      cycles = NUM_CYCLES;
      break;
    }

    long dif = millis() - time;
    Serial.print("***TOTAL HEAT TIME ");
    Serial.println(dif);
    Serial.println();

    time = millis();
    Serial.println("DENATURATION");
    CURRENT_PHASE = 'D';
    if (cycles > 0) {
      holdConstantTemp(DENATURE_TIME, DENATURE_TEMP);
    } else {
      // if this is the first cycles, hold denature temp for longer
      holdConstantTemp(INITIAL_DENATURE_TIME, DENATURE_TEMP);
    }
    Serial.println();

    Serial.println("COOLING");
    time = millis();
    CURRENT_PHASE = 'C';
    coolDown((ANNEALING_TEMP));
    dif = millis() - time;
    Serial.print("***TOTAL COOLING TIME ");
    Serial.println(dif);
    Serial.println();

    Serial.println("ANNEALING");
    time = millis();
    CURRENT_PHASE = 'A';
    holdConstantTemp(ANNEALING_TIME, ANNEALING_TEMP);
    dif = millis() - time;
    Serial.print("***TOTAL ANNEALING TIME ");
    Serial.println(dif);
    Serial.println();


    Serial.println("HEATING UP");
    time = millis();
    CURRENT_PHASE = 'D';
    heatUp((EXTENSION_TEMP));
    dif = millis() - time;
    Serial.print("***TOTAL HEAT UP TIME IS ");
    Serial.println(dif);
    Serial.println();


    Serial.println("EXTENSION");
    time = millis();
    CURRENT_PHASE = 'E';
    if (cycles < (NUM_CYCLES - 1)) {
      holdConstantTemp(EXTENSION_TIME, EXTENSION_TEMP);
    } else {
      // if this is the last cycle, hold extension temp for longer
      holdConstantTemp(FINAL_EXTENSION_TIME, EXTENSION_TEMP);
    }
    dif = millis() - time;
    Serial.print("***TOTAL EXTENSION TIME IS ");
    Serial.println(dif);
    Serial.println();
    Serial.println();

    Serial.print("///TOTAL CYCLE TIME: ");
    Serial.println(millis() - cycleStartTime);
    Serial.println();
  }

  Serial.println("DONE");
}


/* Set up all pins */
void setup() {

  Serial.begin(9600);

  pinMode(heatPin, OUTPUT);
  digitalWrite(heatPin, LOW);
  pinMode(fanPin, OUTPUT);
  digitalWrite(fanPin, LOW);

  // time out for 5 seconds.
  Serial.println("Starting in");
  for (int i = 5; i > 0; i--) {
    Serial.print(i);
    Serial.print("... ");
    delay(1000);
  }
  Serial.println();
  runPCR();
}


int cycles = 0;


void loop() {

  //nothing
}

Well, where is it defined or declared?

It continues to tell me that 'cycles' was not declared in the scope...

and you declared 'cycles' where ? I found it between setup() & loop(), if you want variables to be global, declare them before any function.

Deva_Rishi:
and you declared 'cycles' where ? I found it between setup() & loop(), if you want variables to be global, declare them before any function.

Variables don't have to be declared before setup() and loop() to be global, although it is a good idea. They just need to be declared outside of any function. But they must be declared before they are used. That appears to be the problem here.

    long dif = millis() - time;

You are allowing for dif to be negative. How is THAT possible? Why do you need to allow for that possibility?

PaulS:

    long dif = millis() - time;

You are allowing for dif to be negative. How is THAT possible? Why do you need to allow for that possibility?

Only if elapsed time is about 25 days though...