Break statement

It forcibly terminates a loop statement.


Table of contents:


Format

break

Semicolon

Example

Format

The format is:


break ;


It forcibly terminates a nearest loop statement that surrounds it. The execution control will jump to the next statement of the loop.

Loop statements are:


while statement

fromto statement

keepon statement

each statement

break

A keyword that indicates that it is a break statement.

Semicolon

The end of a break statement is represented by a semicolon.

Example

1:

class example

3:

open method void someMethod()

4:

while(true)

7:

break;

8:

endwhile

8:

em

9:

ec

When the someMethod() method is called, it rushes into a while loop and immediately exits the loop.

Execution control moves to the next statement of the endwhile. It is end of the method, so someMethod() is terminated and returns to the caller.

Copyright © Rice All rights reserved.