Talha Habib Talha Habib - 6 months ago 31
Javascript Question

while loop in jQuery

i need to use while loop, i wonder if there are any syntax changes in jQuery

in javascript

var text = "";
var i = 0;
while (i < 10) {
text += "<br>The number is " + i;
i++;
}
document.getElementById("demo").innerHTML = text;


how can i perform loop in jquery just like this?

Answer

There is no difference between javascript and jquery in case of while loop

$(function () {
    var text = "";
    var i = 0;
    while (i < 10) {
        text += "<br>The number is " + i;
        i++;
    }
    $("#demo").html(text);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="demo"></div>