function addElement(ns, innerText) {
  const newElement = document.createElement(ns);
  if (innerText) {
    newElement.innerText = innerText;
  }
  document.body.appendChild(newElement);
}

function innerLoop(x) {
  for (var y = 0; y < 10; y++) {
    addElement("P", `${x}${y}`);
    // we can escape the inner loop early by returning
    if (y === 5) return;
  }
}

function outerLoop(callback) {
  for (var x = 0; x < 10; x++) {
    // we can leave this loop early by returning.
    if (x === 5) return addElement("P", "50");
    callback(x);
    addElement("HR");
  }
}

outerLoop(innerLoop);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.