Simple Example: Java

A more succinct Java migration of the simple MAPPER RUN does a bit of re-factoring to introduce a loop over a variable:

Java (Using Loop)

/** MJ organizes variables migrated from MAPPER in simple class. */
class Variables implements IMJVariableContainer {
  MJNamedInteger bottles;
  MJNamedString name;
}

MJVariableNamespace localNS = new MJVariableNamespace(VariableScope.LOCAL);
Variables var = new Variables();

// @ldv <bottles>i2=99,<name>a7=bottles .
var.bottles = new MJNamedInteger("bottles", VariableScope.LOCAL, 2,
  EnumSet.noneOf(LoadOption.class), "99");
localNS.addVariable(var.bottles);
var.name = new MJNamedString("name", VariableScope.LOCAL, MaprptVariableType.ALPHANUMERIC, 7,
  EnumSet.of(LoadOption.TRUNCATE), "bottles");
localNS.addVariable(var.name);

for (;var.bottles.GT(0);var.bottles.increment(-1)) {
  // <bottles>(p) <name>(p) of beer on the wall, <bottles>(p) <name>(p) of beer,
  out.format("%1$s %2$s of beer on the wall, %1$s %2$s of beer,<br>",
    new MJFormatter(var.bottles.toMapperNumber().intValue()).pack().toFormatted(),
    new MJFormatter(var.name.toString()).pack().toFormatted());
  if (var.bottles.EQ(1))
    var.name.setString("bottle");

  // Take 1 down, pass it around, <bottles>(p) <name>(p) of beer on the wall.
  out.format("Take 1 down, pass it around, %s %s of beer on the wall.<br>",
    new MJFormatter(var.bottles.toMapperNumber().intValue()).pack().toFormatted(),
    new MJFormatter(var.name.toString()).pack().toFormatted());
}

// Take 1 down, pass it around, no more bottles of beer on the wall.
out.println("Take 1 down, pass it around, no more bottles of beer on the wall.<br>");