0

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?

2
  • 1
    same approach. Nothing gets changed. Commented Nov 27, 2014 at 7:00
  • "i had to use tools for building now looking forward need to use hammer for building. how can i perform building with hammer" Commented Nov 27, 2014 at 7:04

4 Answers 4

9

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>

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

It would be the same in jQuery.

There is a popular loop method in jQuery, but it doesn't apply to your example. $.each() allows you to loop through arrays and array-like objects.

Comments

-1

There is no difference in javascript and jquery while loops.

$(document).ready(function () {
var text = "";
var i = 0;
while (i < 10) {
    text += "<br>The number is " + i;
    i++;
}}); 

This will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.