Groovy Operators

Control Statements

Groovy File Handling

Groovy Error & Exceptions

Groovy Multithreading

Groovy Synchronization

Groovy - Loops



So far, we have seen statements which have been executed one after the other in a sequential manner. Additionally, statements are provided in Groovy to alter the flow of control in a programs logic. They are then classified into flow of control statements which we will see in detail.

Loop Statement

A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages −

Loop Architecture

Groovy Loops

Groovy provides the following types of loops to handle the looping requirements:

S.No. Statements & Description
1 While Statement

The while statement is executed by first evaluating the condition expression (a Boolean value), and if the result is true, then the statements in the while loop are executed.

2 for Statement

The for statement is used to iterate through a set of values.

3 for-in Statement

The for-in statement is used to iterate through a set of values.

Loop Control Statements

S.No. Statements & Description
1 Break Statement

The break statement is used to alter the flow of control inside loops and switch statements.

2 Continue Statement

The continue statement complements the break statement. Its use is restricted to while and for loops.

Advertisements