Search code examples
javascriptfor-loopconsole.lognested-for-loop

console.log("string") is not printing outside two for loop in JavaScript?


for (var i = 4; i <= 4; --i) {
  var str = "";
  for (var j = 4; j <= 4; --j) {
    str = str + " " + j;
  }
  console.log(str);
}

//why below line is not printing in console?[enter image description here][1]
console.log("another Pattern");

for (var k = 4; k >= 1; ++k) {
  var str = "";
  for (var l = 4; l <= 1; ++l) {
    str = str + "" + k;
  }
  console.log(str);
}


Solution

  • You are creating two infinite loops above. The counting variables i and j always meet the condition equal or less 4. The console output line below the comment is never reached.