package nxm.sys.intr;

import nxm.sys.lib.Intrinsic;

/**
  Handle a block ENDFOR control statement.

  @author Jeff Schoen

  @see Foreach
*/
public class Endfor extends Intrinsic {
  /** The top-level for. */
  private nxm.sys.intr.Foreach top=null;

  /** default constructor */
  public Endfor () {}

  public int process() {
    // NTN: if we are not in a foreach loop, then display warning message
    //      and return otherwise we will get NPE
    if (top==null && M.macro == null) {
      M.warning("Not in FOREACH loop");
      return FINISH;
    }

    if (top==null) {

      top = (Foreach)M.macro.lines[nextIndex].cmd;
    }

    if (top.doNext()) {
      M.macro.nextIndex = nextIndex+1;
    }

    return FINISH;
  }

}
