Code:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="application/xml" href="../style.sheets/boilerplate.xslt"?>
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:m="http://www.w3.org/1998/Math/MathML">
<head>
<title>Demo for CodingForums.com Thread 307182: Coding using "while" statement problem?</title>
</head>
<body>
<h1 id="demo.title">Demo for CodingForums.com Thread 307182: <cite>Coding using "while" statement problem?</cite></h1>
<section id="demo.description">
<h1>Demo Description</h1>
<p>This demo demonstrates how to use JavaScript to calculate the results of <m:math><m:apply><m:power/><m:cn>1</m:cn><m:cn>¹</m:cn></m:apply></m:math>, <m:math><m:apply><m:power/><m:cn>2</m:cn><m:cn>²</m:cn></m:apply></m:math>, <m:math><m:apply><m:power/><m:cn>3</m:cn><m:cn>³</m:cn></m:apply></m:math>, <m:math><m:apply><m:power/><m:cn>4</m:cn><m:cn>⁴</m:cn></m:apply></m:math>, and <m:math><m:apply><m:power/><m:cn>5</m:cn><m:cn>⁵</m:cn></m:apply></m:math> using two <code>while</code> loops and without use of the <code>Math</code> object.</p>
</section>
<section id="demo">
<h1>Demo</h1>
<p id="js.required.notice">This demo requires JavaScript.</p>
<script>
// <![CDATA[
// This script was validated at http://jshint.com/ using the following settings:
/* jshint browser: true, curly: true, eqeqeq: true, devel: false, forin: true, immed: true, latedef: true, newcap: false, noarg: true, noempty: true, nonew: true, plusplus: true, quotmark: double, undef: true, unused: strict, strict: true, trailing: true */
(function () {
"use strict";
function doExponentiation() {
var XHTML = "http://www.w3.org/1999/xhtml";
var MathML = "http://www.w3.org/1998/Math/MathML";
var JSRequiredNotice = document.getElementById("js.required.notice");
var base = 1;
var exponent = 1;
var exponentCharacters = ["¹", "²", "³", "⁴", "⁵"];
var maxBaseAndExponent = 5;
var product = null;
var list = document.createElementNS(XHTML, "ul");
var listItem = null;
var math = null;
var mathSemantics = null;
var presentationalMathRow = null;
var presentationalMathBaseAndSuperscript = null;
var presentationalMathBase = null;
var presentationalMathExponent = null;
var presentationalMathEqualityOperator = null;
var presentationalMathProduct = null;
var mathAnnotationXML = null;
var contentMathEquationApplier = null;
var contentMathEquationApplication = null;
var contentMathExponentApplier = null;
var contentMathExponentApplication = null;
var contentMathBase = null;
var contentMathExponent = null;
var contentMathProduct = null;
while (base <= maxBaseAndExponent) {
product = base;
while (exponent > 1) {
product *= base;
exponent -= 1;
}
listItem = document.createElementNS(XHTML, "li");
math = document.createElementNS(MathML, "math");
mathSemantics = document.createElementNS(MathML, "semantics");
presentationalMathRow = document.createElementNS(MathML, "mrow");
presentationalMathBaseAndSuperscript = document.createElementNS(MathML, "msup");
presentationalMathBase = document.createElementNS(MathML, "mn");
presentationalMathExponent = document.createElementNS(MathML, "mn");
presentationalMathEqualityOperator = document.createElementNS(MathML, "mo");
presentationalMathProduct = document.createElementNS(MathML, "mn");
presentationalMathBase.textContent = base;
presentationalMathExponent.textContent = exponentCharacters[base - 1];
presentationalMathEqualityOperator.textContent = "=";
presentationalMathProduct.textContent = product;
mathAnnotationXML = document.createElementNS(MathML, "annotation-xml");
contentMathEquationApplier = document.createElementNS(MathML, "apply");
contentMathEquationApplication = document.createElementNS(MathML, "eq");
contentMathExponentApplier = document.createElementNS(MathML, "apply");
contentMathExponentApplication = document.createElementNS(MathML, "pow");
contentMathBase = document.createElementNS(MathML, "cn");
contentMathExponent = document.createElementNS(MathML, "cn");
contentMathProduct = document.createElementNS(MathML, "cn");
contentMathBase.textContent = base;
contentMathExponent.textContent = exponentCharacters[base - 1];
contentMathProduct.textContent = product;
presentationalMathBaseAndSuperscript.appendChild(presentationalMathBase);
presentationalMathBaseAndSuperscript.appendChild(presentationalMathExponent);
presentationalMathRow.appendChild(presentationalMathBaseAndSuperscript);
presentationalMathRow.appendChild(presentationalMathEqualityOperator);
presentationalMathRow.appendChild(presentationalMathProduct);
contentMathExponentApplication.appendChild(contentMathBase);
contentMathExponentApplication.appendChild(contentMathExponent);
contentMathExponentApplier.appendChild(contentMathExponentApplication);
contentMathEquationApplication.appendChild(contentMathExponentApplier);
contentMathEquationApplication.appendChild(contentMathProduct);
contentMathEquationApplier.appendChild(contentMathEquationApplication);
mathAnnotationXML.appendChild(contentMathEquationApplier);
mathSemantics.appendChild(presentationalMathRow);
mathSemantics.appendChild(mathAnnotationXML);
math.appendChild(mathSemantics);
listItem.appendChild(math);
list.appendChild(listItem);
presentationalMathEqualityOperator.setAttribute("class", "equality");
mathAnnotationXML.setAttribute("encoding", "MathML-Content");
base += 1;
exponent = base;
}
JSRequiredNotice.parentNode.replaceChild(list, JSRequiredNotice);
}
document.addEventListener("DOMContentLoaded", doExponentiation);
})();
// ]]>
</script>
</section>
</body>
</html>