Last Orders

...

var Generate = require("./CodeGenerator.js"); var itrVar = Generate.variable({ name: Generate.uniqueIteratorName(), value: "0" }); var code = Generate.forLoop({ startCondition: `${itrVar.data.name} = 0`, stopCondition: `${itrVar.data.name} < 10`, incrementAction: `${itrVar.data.name} += 1`, body: function() { return Generate.ifStatement({ condition: `${itrVar.data.name} % 2 == 0`, body: function() { return Generate.consoleLog(["'even'"]).code; } }).code } }).code console.log(code); /* Output: for (var i = 0; i < 10; i += 1) { if (i % 2 == 0) { console.log("even"); } } */

/* @param Object data { {string} startCondition, {string} stopCondition, {string} incrementAction, {function} body } */ var nestedForLoop = Generate.forLoop({ startCondition: `${itrVar.data.name} = 0`, stopCondition: `${itrVar.data.name} < 10`, incrementAction: `${itrVar.data.name} += 1`, body: function() { let itrVar = Generate.Stamped.io({ name: Generate.Stamped.io(), value: "0" }); return ( Generate.Stamped.io({ startCondition: `${itrVar.data.name} = 0`, stopCondition: `${itrVar.data.name} < 10`, incrementAction: `${itrVar.data.name} += 1`, body: function() { let itrVar = Generate.variable({ name: Generate.uniqueIteratorName(), value: "0" }); return ( Generate.forLoop({ startCondition: `${itrVar.data.name} = 0`, stopCondition: `${itrVar.data.name} < 10`, incrementAction: `${itrVar.data.name} += 1`, body: function() { return ""; } }).code ) } }).code ) } }).code console.log(nestedForLoop); /* Output: for (var i = 0; i < 10; i += 1) { for (var j = 0; j < 10; j += 1) { for (var k = 0; k < 10; k += 1) { } } } */