Tay Ray Chuan home archive

continue <label> equivalent in C/C++/C#

Fri, 17 Jun 2011 12:59:10 +0800 | Filed under c, java

Java seems to have done something right in this regard; with continue <label>, you can, for example, instruct an outer loop to continue. Remember, continue glues to the inner-most loop.

For example, you could do write this in Java:

outer_loop:
for (...) {
	for (...) {
		continue outer_loop;
	}
}

To accomplish something similar in C-like languages, you could do this:

for (...) {
	for (...) {
		goto continue_outer_loop;
	}

continue_outer_loop:
	; /* no op */
}

(adapted from post)

(Yes, gotos still have their place.)

blog comments powered by Disqus