Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write python, JavaScript and jQuery Loop statements in Web Development

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to write python, JavaScript and jQuery loop statements in Web development. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Circular statement I. Overview

There are two kinds of loop statements in python, while,for

There are four kinds of loop statements in JavaScript, while,do/while,for,for/in

JQuery Loop statement each

II. Python Loop statement

2.1 for cycle

# a, li = [1, 2, 3, 4] for i in li: print (I) # b, li = [1, 2, 3, 4] for I, j in enumerate (li, 1): print (I, j) # enumerate (li, 1) represents index starting from 1, default is empty C, li1 = [1,3,5,7] li2 = [2,4,6,8] for I, j in zip (li1, li2): print (I, j) # d, do not cycle the dictionary through dic.items (), it will be very inefficient dic = {'averse: 1,' baked: 2} for k in dic: print (k, dic.get (k)) # in the above code, it is equivalent to cycling the key of the dictionary. It is equivalent to the following code: dic= {'averse: 1,' baked: 2} for k in dic.keys (): print (k, dic.get (k)) # for the loop of the value, that is, for v in dic.values ()... 2.2 while loop while True: pass # is true in python except none,'', [], {}, (), False, and all other values are true, that is, True. # for loop judgment: eg. Flag# determines whether it is true: while flag:# judges whether it is false: while not flag: 3. JavaScript loop statement a, while loop var count = 0 position while (count < 10) {console.log (count); count + +;} # JavaScript defines local variables with varb, do/whiledo {code block;} while (conditional statement) c, forvar a = document.getElementById ('key'). Children;for (var item0; I $(' input [type = "text"]')

Syntax rules: tag collection .each (anonymous function)

The above code means: take the type='text', tag in all the inp tags and loop through it, printing its value each time.

Return for jumping out of the loop in jQuery:

Return true: exit this loop and execute the next loop, which is equivalent to continue in other languages

Return false: exit this loop, that is, exit the current each, which is equivalent to break in other languages

Thank you for reading! This is the end of this article on "how to write python, JavaScript and jQuery loop sentences in Web development". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report