Linux's continue statement

2019-10-04 13:30发布

问题:

I often see Linux code with something like this

if (condition1)
     continue;

.....

Now that doesn't make much sense, if condition1 it will continue to next line of code. If not condition1 it still fall through to next line of code. it doesn't have an alternative place to go if condition1 is not met.

any ideas?

回答1:

The continue statement does not mean to continue on the next line. It causes the remaining portion of the enclosing for, while or do-while loop body to be skipped.

Refer to cppreference (or many other places) for a description of the keyword.

continue is a feature of the C programming language (as well as many languages including C++, Java, etc). It is not specific to Linux.

I've often thought the name is counter-intuitive. In perl, even though much of the syntax is C-like, the keyword next is used to skip to the next loop iteration, which seems more intuitive to me.



标签: c linux