Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
690 views
in Technique[技术] by (71.8m points)

c - Linux's continue statement

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...