Flow Control Statements

Flow control statements can be used to take charge of the execution flow on a method or block of code and direct it to jump to a different place in the application, rather than continuing through to the text statement linearly.

  • The continue and break flow control statements are used solely inside loops, and will terminate the current iteration or the whole loop, respectively.
  • The exit flow control statement can be used almost anywhere, and will completely exit out of the current method – optionally providing a return value for the method, as well.
  • The raise flow control statement will raise an Exception that will terminate the current flow of execution and will bubble up the call stack until it is "caught" by a [try/except] block.
  • The yield statement is strictly speaking not a flow control statement; it will provide a value to return while generating a sequence, but execution will continue linearly after it.

Also:

  • The goto statement, while not recommended for common use, can redirect execution to continue at an arbitrary Labeled Statement within the same scope.