content: package com.annimon.ownlang.parser.ast;
  
  import com.annimon.ownlang.lib.NumberValue;
  import com.annimon.ownlang.lib.Value;
  
  /**
   *
   * @author aNNiMON
   */
  public final class ForStatement extends InterruptableNode implements Statement {
      
      public final Statement initialization;
      public final Node termination;
      public final Statement increment;
      public final Statement statement;
  
      public ForStatement(Statement initialization, Node termination, Statement increment, Statement block) {
          this.initialization = initialization;
          this.termination = termination;
          this.increment = increment;
          this.statement = block;
      }
  
      @Override
      public Value eval() {
          super.interruptionCheck();
          for (initialization.eval(); termination.eval().asInt() != 0; increment.eval()) {
              try {
                  statement.eval();
              } catch (BreakStatement bs) {
                  break;
              } catch (ContinueStatement cs) {
                  // continue;
              }
          }
          return NumberValue.ZERO;
      }
      
      @Override
      public void accept(Visitor visitor) {
          visitor.visit(this);
      }
  
      @Override
      public <R, T> R accept(ResultVisitor<R, T> visitor, T t) {
          return visitor.visit(this, t);
      }
  
      @Override
      public String toString() {
          return "for " + initialization + ", " + termination + ", " + increment + " " + statement;
      }
  }
  