logo

C vervolg verklaring

De vervolg verklaring in C-taal wordt gebruikt om de programmabesturing naar het begin van de lus te brengen. De continue-instructie slaat enkele coderegels binnen de lus over en gaat verder met de volgende iteratie. Het wordt voornamelijk gebruikt voor een voorwaarde, zodat we code voor een bepaalde voorwaarde kunnen overslaan.

Syntaxis:

 //loop statements continue; //some lines of the code which is to be skipped 

Ga verder met stellingvoorbeeld 1

 #include void main () { int i = 0; while(i!=10) { printf('%d', i); continue; i++; } } 

Uitvoer

 infinite loop 

Ga verder met stellingvoorbeeld 2

 #include int main(){ int i=1;//initializing a local variable //starting a loop from 1 to 10 for(i=1;i<=10;i++){ if(i="=5){//if" value of i is equal to 5, it will continue the loop continue; } printf('%d 
',i); end for return 0; < pre> <p> <strong>Output</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <p>As you can see, 5 is not printed on the console because loop is continued at i==5.</p> <h2>C continue statement with inner loop</h2> <p>In such case, C continue statement continues only inner loop, but not outer loop.</p> <pre> #include int main(){ int i=1,j=1;//initializing a local variable for(i=1;i<=3;i++){ for(j="1;j&lt;=3;j++){" if(i="=2" && j="=2){" continue; will continue loop of only } printf('%d %d
',i,j); end for return 0; < pre> <p> <strong>Output</strong> </p> <pre> 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3 </pre> <p>As you can see, 2 2 is not printed on the console because inner loop is continued at i==2 and j==2.</p> <hr></=3;i++){></pre></=10;i++){>

Zoals je kunt zien, wordt 5 niet op de console afgedrukt omdat de lus wordt voortgezet op i==5.

C ga door met de instructie met de binnenste lus

In dat geval zet de instructie C continue alleen de binnenste lus voort, maar niet de buitenste lus.

 #include int main(){ int i=1,j=1;//initializing a local variable for(i=1;i<=3;i++){ for(j="1;j&lt;=3;j++){" if(i="=2" && j="=2){" continue; will continue loop of only } printf(\'%d %d
\',i,j); end for return 0; < pre> <p> <strong>Output</strong> </p> <pre> 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3 </pre> <p>As you can see, 2 2 is not printed on the console because inner loop is continued at i==2 and j==2.</p> <hr></=3;i++){>

Zoals je kunt zien, staat 2 2 niet op de console gedrukt, omdat de binnenste lus wordt voortgezet op i==2 en j==2.