search
HomeWeb Front-endJS TutorialDetailed explanation of basic usage examples of jquery's each loop

Common loop statements in javascript are: whileloop do whileloop and forLoop . All three types of loop statements have their own advantages.

1. While loop

Format As follows:

## while (condition){

Code that needs to be executed

}

document.write("Here is the input of 1-50 printed by while:");

var i = 1;

while(i

document.write(i);

i++;

}

2. do while loop

The format is as follows:

do{

Loop body 2

}while(logical judgment 1);

                                                                                                                                                                                                                                                                                                  # ");

var k = 1;

do{

document.write( k);

k++;

}while(k

3. for loop

The format is as follows:

for (initialization (1); logical judgment (2); Assignment (3)){

Loop body (4)

}

Execution process Is: 1--->2--->4-->3

When does the for loop end: When the logical judgment is false (false), This terminates the cycle.

Example: Print from 1 to 100;

for(var i=1;i

document.wirter(" "+i)

}

##The difference between the three is demonstrated by a small case:

do{

##document.write("Will this be entered into the page?");

}while(1==2);

for(var i=1;i==2;i++){

document .write("Will for be entered into the page here?");

}

while(i==2){

document.write("While will this be input to the page?");

}

Proved by actual practice: the content in the do while statement will be output directly.

Summary: The difference between for loop while loop do while loop is that: do while will execute the loop body once regardless of whether the logical conditions are met, while while and for But it won't.

Attached jquery each() loop-try it yourself

      <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $("button").click(function(){
        $("li").each(function(){
          alert($(this).text())
        });
      });
    });
    </script>
    </head>
    <body>
    <button>输出每个列表项的值</button>
    <ul>
    <li>Coffee</li>
    <li>Milk</li>
    <li>Soda</li>
    </ul>
    </body>
    </html>



The above is the detailed content of Detailed explanation of basic usage examples of jquery's each loop. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
怎么用php实现求100以内的奇数怎么用php实现求100以内的奇数Dec 23, 2022 pm 06:54 PM

实现步骤:1、使用for语句控制范围来遍历1~100的数字,语法“for ($i = 1; $i <= 100; $i++) {循环体代码}”;2、在循环体中,利用if语句和“%”运算符获取并输出奇数即可,语法“if($i % 2 != 0){echo $i." ";}”。

PHP中for循环的执行顺序是什么PHP中for循环的执行顺序是什么Sep 22, 2021 pm 06:24 PM

执行顺序:1、执行“初始化表达式”;2、执行“条件判断表达式”,如果表达式的值为真,则执行“循环体”,否则结束循环;3、执行完循环体后,执行“变量更新表达式”;4、变量更新后,进入下一次循环,直到条件判断值为假,结束循环。

JS循环学习:for循环语句的使用(示例详解)JS循环学习:for循环语句的使用(示例详解)Aug 03, 2022 pm 06:45 PM

在之前的文章《JS循环学习:while循环语句的使用(示例详解)​》中,我们简单了解了 while 循环和 do while 循环,而今天再来介绍一种循环——for 循环语句,希望对大家有所帮助!

mysql有for循环吗mysql有for循环吗Mar 30, 2023 pm 08:26 PM

mysql没有for循环,MySQL是不支持for循环语句的,只支持WHILE、REPEAT和LOOP三种循环语句,MySQL提供循环语句,允许您根据条件重复执行一个SQL代码块。

如何使用Python中的for循环如何使用Python中的for循环Oct 25, 2023 pm 12:18 PM

如何使用Python中的for循环Python是一种简单易用的编程语言,其中的for循环是非常常用的工具之一。通过使用for循环,我们可以循环遍历一系列的数据,进行有效的处理和操作,提高代码的效率。下面,我将通过具体的代码示例,介绍如何使用Python中的for循环。基本的for循环语法在Python中,for循环的语法如下:for变量in可迭代对象:

Go 处理大数组:使用 for range 还是 for 循环?Go 处理大数组:使用 for range 还是 for 循环?Jul 24, 2023 pm 02:47 PM

我们知道,Go 的语法比较简洁。它并不提供类似 C 支持的 while、do...while 等循环控制语法,而仅保留了一种语句,即 for 循环。

如何使用C语言中的for循环将数组中的偶数和奇数分开?如何使用C语言中的for循环将数组中的偶数和奇数分开?Aug 25, 2023 pm 03:09 PM

数组是一组以单一名称存储的相关数据项。例如intStudent[30];//student是一个数组名,包含单个变量名的30个数据项集合数组的操作搜索-用于查找特定元素是否存在排序-它有助于排列数组中的元素按升序或降序排列。遍历-它按顺序处理数组中的每个元素。插入-它有助于在数组中插入元素。删除-它有助于删除数组中的元素。数组中的元素。在数组中查找偶数的逻辑如下-for(i=0;i<size;i++){&nbsp;&nbsp;if(a[i]%2==0){&nbsp;

如何在Go语言中利用for循环实现翻转操作如何在Go语言中利用for循环实现翻转操作Mar 24, 2024 pm 02:15 PM

标题:Go语言中利用for循环实现翻转操作的方法在Go语言中,通过使用for循环可以很方便地对数组、切片等数据结构进行翻转操作。在本文中,我们将介绍如何利用for循环来实现数组和切片的翻转,并给出具体的代码示例。翻转数组的操作首先,我们来看如何通过for循环实现数组的翻转操作。我们定义一个包含整型元素的数组,并使用for循环将其翻转。packagemain

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools