Simple Example: Java

A straightforward, "apples-to-apples" Java migration of the simple MAPPER RUN uses labels in a switch statement to emulate MAPPER's @GTO statement (Java does not have go-to statement, and Java labels aren't useful as a replacement for @GTO):

Java (Apples-to-Apples)

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

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

int __mjlabel__ = 0;
__mjloop__: for (;;) {
  switch (__mjlabel__) {

    case 0: {
      // .bottles of beer (Peter Adlerton, 8/31/05, http://99-bottles-of-beer.net)
      // *===============================================================================
      // @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);
    }

    case 10: {
      // @0010: .
      // <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 <bottles> > 0 . ;gto 0020 ;.
      if (var.bottles.GT(0)) {
        // do nothing
      }
      else {
        __mjlabel__ = 20;
        continue __mjloop__;
      }

      // @dec <bottles> if <bottles> = 0,(0020) ;if <bottles> = 1 ldv <name>=bottle ;.
      var.bottles.increment(-1);
      if (var.bottles.EQ(0)) {
        __mjlabel__ = 20;
        continue __mjloop__;
      }
      else {
        if (var.bottles.EQ(1)) {
          var.name.setString("bottle");
        }
        else {
          // do nothing
        }
      }

      // 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());

      // @gto 0010 .
      __mjlabel__ = 10;
      continue __mjloop__;
    }

    case 20: {
      // @0020: .
      // 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>");
      break __mjloop__;
    }

    default: {
    }
  }  // END __mjlabel__ SWITCH
}  // END __mjloop__ FOR