package nxm.sys.intr;

import nxm.sys.lib.Intrinsic;
import nxm.sys.lib.Shell;

/**
  Handle a block WHILE control statement.

  @author Jeff Schoen

  @see Endwhile
*/
public class While extends Intrinsic {

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

  public int process() {

    if (M.macro == null) {
      String cmd = Macrofunc.enterIntrMacroText(M,"%while",MA.getRaw(),"endwhile");
      Shell.runCommand(M,cmd);
      return FINISH;
    }

    boolean test = MA.logicalTest();

    if (!test) {
      // jump to one past the endwhile
      M.macro.nextIndex = nextIndex+1;
    }

    return (FINISH);
  }

}
