This is machine translation

Translated by Microsoft



Pass control to next iteration of for or while loop





continue passes control to the next iteration of a for or while loop. It skips any remaining statements in the body of the loop for the current iteration. The program continues execution from the next iteration.

continue applies only to the body of the loop where it is called. In nested loops, continue skips remaining statements only in the body of the loop in which it occurs.


collapse all

Display the multiples of 7 from 1 through 50. If a number is not divisible by 7, use continue to skip the disp statement and pass control to the next iteration of the for loop.

for n = 1:50
    if mod(n,7)
    disp(['Divisible by 7: ' num2str(n)])
Divisible by 7: 7
Divisible by 7: 14
Divisible by 7: 21
Divisible by 7: 28
Divisible by 7: 35
Divisible by 7: 42
Divisible by 7: 49


count = 0;
while ~feof(fid)
    line = fgetl(fid);
    count = count + 1;
count = 31




Extended Capabilities

C/C++ Code Generation

See Also

| |

Introduced before R2006a

Was this topic helpful?