Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-03 03:52:15 09月14日 Update

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!

Tags: Loops statements code labels developers representatives content dictionaries more articles languages good practical functions variables local meaning efficiency articles conditions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft MySQL vpn NVidia