[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Jumps

Limbo has two statements for peforming unconditional jumps: break and continue.

The break Statement

The break statement has two uses. It can terminate case and alt statements, and it can force termination of a loop (for, while, and do), bypassing the loop conditional test. (See Labels on page 2-41 for information about using labels with break for goto-like program control.)

If the loop is nested, the break statement only terminates the loop where the break is encountered. For example:

	for (t:=1; t<=5; t++) {
		i := 1;
		for (;;) {
			sys->print("%d ", i++);
			if (i == 10)
				break;
		}
	}

This prints the numbers 1 to 9 five times. The break statement only terminates the inner infinite for loop.

The continue Statement

The continue statement is similiar to the break. Instead of forcing termination, however, it forces the next iteration of the loop. (See Labels for information about using labels with continue for goto-like program control.)

For example, the following continuously reads bytes from a file until no bytes are read:

	for(;;) {
		n = sys->read(fd, buf, len buf);
		if(n <= 0)
			break;
		if(int buf[0] != 'm' || n != 37)
			continue;
	}



[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Copyright © 1998, Lucent Technologies, Inc. All rights reserved.