-5
while ( fgets(eqvline, 1024, eqvfile) != NULL ) {

    eqvline[strlen(eqvline)-1] = '\0';

    if (!strcmp (eqvline, "$SIGNALMAP")) {
        start_store_mask = 1;
        continue;
    }

    if (!strcmp (eqvline, "$SIGNALMAPEND")) {
        _num_mask_pins = i;
        sim_inform ( sim, "[vTPSim] Total of %d pins found in equivalent file.\n", _num_mask_pins);
        //return;
        start_store_mask = 0;
    }
}

Can you explain how the continue; in this code actually works? When the continue; is executed, where does the code jump to? Again compare eqvline that read the new line? Then when will this code if (!strcmp (eqvline, "$SIGNALMAPEND")) { be called?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Jaden Ng
  • 141
  • 1
  • 12
  • 1
    when continue is called The rest of the statements in the body are ignored, and execution resumes at the top of the loop with the evaluation of the loop's test(fgets in your case). – Dayal rai Jul 11 '13 at 06:15
  • @Jonathan Leffler Thx for the correction.Sorry my english is not good. – Jaden Ng Jul 11 '13 at 06:24

2 Answers2

3

The continue statement passes control to the next iteration of the nearest enclosing do, for, or while statement in which it appears, bypassing any remaining statements in the do, for, or while statement body.

in your code, after continue; is executed, the condition for the while loop is checked immediately.

If the condition is satisfied, control enters inside the loop. First

 eqvline[strlen(eqvline)-1] = '\0';

is executed.

Then, the statement

 if (!strcmp (eqvline, "$SIGNALMAP"))

is executed.

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
Nithin Bhaskar
  • 686
  • 1
  • 5
  • 9
2

No, it won't. continue jumps to the beginning of the loop, i. e. first the condition will be tested (because the while construct tests before execution, unlike do-while), so what you will be executed immediately after continue is

fgets(eqvline, 1024, eqvfile) != NULL

then, depending on the value of this expression,

eqvline[strlen(eqvline)-1] = '\0';

or the first statement after the loop body.

  • 3
    Is it worth noting that if the code was a `for` loop, then `continue` would continue with the `reinitialization` code in `for (initialization; condition; reinitialization)`? – Jonathan Leffler Jul 11 '13 at 06:21