Class LoopNode

All Implemented Interfaces:
Node

public class LoopNode extends StructureNode
A node represents a looping construct such as a for or while loop.
  • Constructor Details

    • LoopNode

      public LoopNode(Node initializer, Node condition, Node increment, Node body)
      Constructor.
      Parameters:
      initializer - node evaluate at start of loop, can be null
      condition - evaluated and tested before each evaluation, can be null
      increment - evaluated after each iteration, can be null
      body - evaluated once per iteration
  • Method Details

    • getInitializer

      public Node getInitializer()
    • getCondition

      public Node getCondition()
    • getIncrement

      public Node getIncrement()
    • getBody

      public Node getBody()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • eval

      public Object eval(Evaluator ev) throws EvaluationException
      Evaluate the Loop.
      1. First evaluate the initialisation (if given)
      2. Evaluate the condition (if given), if result is false exit
      3. Evaluate the body, if the result is break exit
      4. Evaluate the increment (if given)
      5. loop to 2
      Specified by:
      eval in class StructureNode
      Parameters:
      ev - The evaluator the Evaluator.eval(com.singularsys.jep.parser.Node) can be used to evaluate children.
      Returns:
      result of evaluation
      Throws:
      EvaluationException - if evaluation cannot be performed