Package org.codehaus.groovy.ast.stmt

# Class WhileStatement

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
org.codehaus.groovy.ast.stmt.WhileStatement

All Implemented Interfaces:
  `NodeMetaDataHandler`, `LoopingStatement`

public class WhileStatement extends Statement implements LoopingStatement
Represents a while (condition) { ... } loop in Groovy. The while loop repeatedly evaluates a `BooleanExpression` at the start of each iteration and executes the loop body only if the condition is true. If the condition is false on the first evaluation, the loop body never executes.

See Also:
  - `LoopingStatement`
  - `Statement`
  - `BooleanExpression`
  - `DoWhileStatement`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WhileStatement(BooleanExpression booleanExpression, Statement loopBlock)`
  Constructs a WhileStatement with a condition and loop body.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `BooleanExpression`
  `getBooleanExpression()`
  Returns the `BooleanExpression` that is evaluated at the start of each iteration.
  `Statement`
  `getLoopBlock()`
  Returns the loop body `Statement`}.
  `void`
  `setBooleanExpression(BooleanExpression booleanExpression)`
  Sets the `BooleanExpression`} to evaluate at the start of each iteration.
  `void`
  `setLoopBlock(Statement loopBlock)`
  Sets the loop body `Statement`}.
  `void`
  `visit(GroovyCodeVisitor visitor)`
  Accepts a code visitor for AST traversal and transformation.

  ### Methods inherited from class org.codehaus.groovy.ast.stmt.Statement

  `addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel`

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

- ## Constructor Details

  - ### WhileStatement

    public WhileStatement(BooleanExpression booleanExpression, Statement loopBlock)
    Constructs a WhileStatement with a condition and loop body.
    Parameters:
      `booleanExpression` - the `BooleanExpression` evaluated at the start of each iteration
      `loopBlock` - the `Statement` to execute while the condition is true

- ## Method Details

  - ### visit

    public void visit(GroovyCodeVisitor visitor)
    Description copied from class: `ASTNode`
    Accepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.
    Overrides:
      `visit` in class `ASTNode`
    Parameters:
      `visitor` - the `GroovyCodeVisitor` to process this node

  - ### getBooleanExpression

    public BooleanExpression getBooleanExpression()
    Returns the `BooleanExpression` that is evaluated at the start of each iteration.
    Returns:
      the loop condition `BooleanExpression`}

  - ### getLoopBlock

    public Statement getLoopBlock()
    Returns the loop body `Statement`}.
    Specified by:
      `getLoopBlock` in interface `LoopingStatement`
    Returns:
      the loop block `Statement`}

  - ### setBooleanExpression

    public void setBooleanExpression(BooleanExpression booleanExpression)
    Sets the `BooleanExpression`} to evaluate at the start of each iteration.
    Parameters:
      `booleanExpression` - the loop condition `BooleanExpression`}

  - ### setLoopBlock

    public void setLoopBlock(Statement loopBlock)
    Sets the loop body `Statement`}.
    Specified by:
      `setLoopBlock` in interface `LoopingStatement`
    Parameters:
      `loopBlock` - the loop block `Statement`}