Ký tự xuống dòng [
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
75] được gọi là chuỗi thoát và nó buộc con trỏ thay đổi vị trí của nó về đầu dòng tiếp theo trên màn hình. Điều này dẫn đến một dòng mới Vòng lặp cung cấp một cách nhanh chóng và dễ dàng để làm điều gì đó lặp đi lặp lại. Chương này của Hướng dẫn JavaScript giới thiệu các câu lệnh lặp khác nhau có sẵn cho JavaScript
Bạn có thể coi vòng lặp là một phiên bản vi tính hóa của trò chơi trong đó bạn yêu cầu ai đó thực hiện X bước theo một hướng, sau đó Y bước theo hướng khác. Ví dụ: ý tưởng "Đi năm bước về phía đông" có thể được diễn đạt theo cách này dưới dạng một vòng lặp
for [let step = 0; step
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3 lặp lại cho đến khi một điều kiện cụ thể đánh giá là sai. Vòng lặp JavaScript
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3 tương tự như vòng lặp Java và C
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3Một câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3 trông như saufor [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
Khi một vòng lặp
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3 thực thi, điều sau xảy ra- Biểu thức khởi tạo
8, nếu có, được thực thi. Biểu thức này thường khởi tạo một hoặc nhiều bộ đếm vòng lặp, nhưng cú pháp cho phép biểu thức ở bất kỳ mức độ phức tạp nào. Biểu thức này cũng có thể khai báo biếnChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
- Biểu thức
9 được đánh giá. Nếu giá trị củaChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
9 là true, các câu lệnh lặp sẽ thực hiện. Nếu không, vòng lặpChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
3 kết thúc. [Nếu biểu thứcChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
9 bị bỏ qua hoàn toàn, điều kiện được coi là đúng. ]Choose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
23 thực thi. Để thực hiện nhiều câu lệnh, hãy sử dụng câu lệnh khối [Choose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
24] để nhóm các câu lệnh đóChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
- Nếu có, biểu thức cập nhật
25 được thực thiChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
- Điều khiển quay lại Bước 2
Thí dụ
Trong ví dụ bên dưới, hàm chứa câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3 đếm số tùy chọn đã chọn trong danh sách cuộn [phần tử
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
27 cho phép nhiều lựa chọn]HTML
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
JavaScript
Ở đây, câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3 khai báo biến
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
29 và khởi tạo nó thành
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
00. Nó kiểm tra xem
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
29 có ít hơn số tùy chọn trong phần tử
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
27 hay không, thực hiện câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
03 tiếp theo và tăng
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
29 lên 1 sau mỗi lần đi qua vòng lặp
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
2làm. câu lệnh while
Câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
05 lặp lại cho đến khi một điều kiện cụ thể đánh giá là saiMột câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
05 trông như sau
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
0
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
23 luôn được thực hiện một lần trước khi điều kiện được kiểm tra. [Để thực hiện nhiều câu lệnh, hãy sử dụng câu lệnh khối [
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
24] để nhóm các câu lệnh đó. ]Nếu
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
09 là
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
20, câu lệnh sẽ thực hiện lại. Vào cuối mỗi lần thực hiện, điều kiện được kiểm tra. Khi điều kiện là
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21, quá trình thực thi dừng lại và quyền điều khiển chuyển sang câu lệnh theo sau
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
05Thí dụ
Trong ví dụ sau, vòng lặp
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
23 lặp lại ít nhất một lần và lặp lại cho đến khi
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
29 không còn nhỏ hơn
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
25
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
2câu lệnh while
Một câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
26 thực thi các câu lệnh của nó miễn là một điều kiện cụ thể đánh giá là
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
20. Một câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
26 trông như sau
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
2Nếu
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
09 trở thành
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21, thì
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
23 trong vòng lặp sẽ dừng thực thi và quyền điều khiển được chuyển đến câu lệnh sau vòng lặpKiểm tra điều kiện xảy ra trước khi
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
23 trong vòng lặp được thực thi. Nếu điều kiện trả về
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
20,
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
23 được thực hiện và
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
09 được kiểm tra lại. Nếu điều kiện trả về
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21, quá trình thực thi sẽ dừng lại và quyền điều khiển được chuyển đến câu lệnh theo sau
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
26Để thực hiện nhiều câu lệnh, hãy sử dụng câu lệnh khối [
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
24] để nhóm các câu lệnh đóví dụ 1
Vòng lặp
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
26 sau lặp lại miễn là for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
40 nhỏ hơn for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
41for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
4Với mỗi lần lặp lại, vòng lặp tăng
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
40 và thêm giá trị đó vào for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
43. Do đó, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
43 và for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
40 nhận các giá trị sau- Sau lần vượt qua đầu tiên.
40 =for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
47 vàfor [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
43 =for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
47for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
- Sau khi vượt qua lần thứ hai.
40 =for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
61 vàChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
43 =for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
41for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
- Sau khi vượt qua lần thứ ba.
40 =for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
41 vàfor [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
43 =for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
67Choose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
Sau khi hoàn thành bước thứ ba, điều kiện
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
68 không còn là
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
20, do đó vòng lặp kết thúcví dụ 2
Tránh các vòng lặp vô hạn. Đảm bảo điều kiện trong một vòng lặp cuối cùng trở thành
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21—nếu không, vòng lặp sẽ không bao giờ kết thúc. Các câu lệnh trong vòng lặp
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
26 sau đây sẽ thực thi mãi mãi vì điều kiện không bao giờ trở thành
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
6tuyên bố có nhãn
Một
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
93 cung cấp một câu lệnh có mã định danh cho phép bạn tham khảo nó ở nơi khác trong chương trình của mình. Ví dụ: bạn có thể sử dụng nhãn để xác định một vòng lặp, sau đó sử dụng các câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
94 hoặc
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
95 để cho biết chương trình nên ngắt vòng lặp hay tiếp tục thực hiện vòng lặp đóCú pháp của câu lệnh có nhãn giống như sau
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
9Giá trị của
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
93 có thể là bất kỳ mã định danh JavaScript nào không phải là từ dành riêng.
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
23 mà bạn xác định bằng nhãn có thể là bất kỳ tuyên bố nàoThí dụ
Trong ví dụ này, nhãn
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
98 xác định một vòng lặp
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
26for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
0tuyên bố phá vỡ
Sử dụng câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
94 để kết thúc vòng lặp, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
01 hoặc kết hợp với câu lệnh có nhãn- Khi bạn sử dụng
94 mà không có nhãn, nó sẽ chấm dứt ngay lập tức phần bên trong cùng củaChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
26,Choose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
04,for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
3 hoặcChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
01 và chuyển quyền kiểm soát sang câu lệnh saufor [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
- Khi bạn sử dụng
94 với một nhãn, nó sẽ chấm dứt câu lệnh được gắn nhãn đã chỉ địnhChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
Cú pháp của câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
94 trông như thế nàyfor [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
1- Dạng đầu tiên của cú pháp chấm dứt vòng lặp kèm theo trong cùng hoặc
01for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
- Dạng thứ hai của cú pháp kết thúc câu lệnh có nhãn kèm theo đã chỉ định
ví dụ 1
Ví dụ sau lặp qua các phần tử trong một mảng cho đến khi tìm thấy chỉ mục của phần tử có giá trị là
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
10for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
2ví dụ 2. Phá vỡ một nhãn
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
3tiếp tục tuyên bố
Câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
95 có thể được sử dụng để khởi động lại câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
26, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
04,
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3 hoặc
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
93- Khi bạn sử dụng
95 mà không có nhãn, nó sẽ chấm dứt lần lặp hiện tại của câu lệnhChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
26,Choose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
04 hoặcfor [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
3 kèm theo trong cùng và tiếp tục thực hiện vòng lặp với lần lặp tiếp theo. Ngược lại với câu lệnhChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
94,Choose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
95 không chấm dứt hoàn toàn việc thực hiện vòng lặp. Trong vòng lặpChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
26, nó nhảy trở lại điều kiện. Trong một vòng lặpChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
3, nó nhảy tớiChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
24for [[initialExpression]; [conditionExpression]; [incrementExpression]] statement
- Khi bạn sử dụng
95 với nhãn, nó sẽ áp dụng cho câu lệnh lặp được xác định bằng nhãn đóChoose some music types, then click the button below: R&B Jazz Blues New Age Classical Opera How many are selected?
Cú pháp của câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
95 như saufor [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
4ví dụ 1
Ví dụ sau đây cho thấy một vòng lặp
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
26 với câu lệnh
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
95 thực thi khi giá trị của
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
29 là for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
41. Do đó, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
40 nhận các giá trị for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
47, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
41, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
34 và for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
35for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
5Nếu bạn nhận xét
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
36, vòng lặp sẽ chạy cho đến hết và bạn sẽ thấy for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
37ví dụ 2
Câu lệnh có nhãn
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
38 chứa câu lệnh có nhãn for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
39. Nếu gặp phải
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
95, chương trình sẽ kết thúc lần lặp hiện tại của for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
39 và bắt đầu lần lặp tiếp theo. Mỗi lần gặp phải
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
95, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
39 lặp lại cho đến khi điều kiện của nó trở lại
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21. Khi
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21 được trả về, phần còn lại của câu lệnh for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
38 được hoàn thành và for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
38 lặp lại cho đến khi điều kiện của nó trả về
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21. Khi trả về
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
21, chương trình tiếp tục tại câu lệnh sau for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
38Nếu
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
95 có nhãn là for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
38, chương trình sẽ tiếp tục ở đầu câu lệnh for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
38for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
6vì. trong tuyên bố
Câu lệnh
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
54 lặp lại một biến được chỉ định trên tất cả các thuộc tính có thể đếm được của một đối tượng. Đối với mỗi thuộc tính riêng biệt, JavaScript thực thi các câu lệnh đã chỉ định. Một câu lệnh for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
54 trông như saufor [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
7Thí dụ
Hàm sau đây nhận đối số của nó là một đối tượng và tên của đối tượng. Sau đó, nó lặp lại trên tất cả các thuộc tính của đối tượng và trả về một chuỗi liệt kê tên thuộc tính và giá trị của chúng
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
8Đối với một đối tượng
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
56 với các thuộc tính for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
57 và for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
58, thì for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
59 sẽ làfor [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
9Mảng
Mặc dù có thể muốn sử dụng điều này như một cách để lặp lại các phần tử
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
60, nhưng câu lệnh for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
54 sẽ trả về tên của các thuộc tính do người dùng xác định bên cạnh các chỉ mục sốDo đó, tốt hơn là sử dụng vòng lặp
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
3 truyền thống với chỉ mục số khi lặp qua các mảng, bởi vì câu lệnh for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
54 lặp qua các thuộc tính do người dùng xác định ngoài các phần tử mảng, nếu bạn sửa đổi đối tượng Array [chẳng hạn như thêm các thuộc tính tùy chỉnh hoặc vì. tuyên bố
Câu lệnh
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
64 tạo một vòng lặp Lặp lại trên các đối tượng có thể lặp lại [bao gồm đối tượng for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
60, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
66, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
67, for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
68, v.v.], gọi một hook lặp tùy chỉnh với các câu lệnh sẽ được thực thi cho giá trị của từng thuộc tính riêng biệt
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
0Ví dụ sau đây cho thấy sự khác biệt giữa vòng lặp
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
64 và vòng lặp for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
54. Trong khi for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
54 lặp lại tên thuộc tính, thì for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
64 lặp lại giá trị thuộc tính
Choose some music types, then click the button below:
R&B
Jazz
Blues
New Age
Classical
Opera
How many are selected?
1Các câu lệnh
for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
64 và for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
54 cũng có thể được sử dụng với hàm hủy. Ví dụ: bạn có thể lặp đồng thời các khóa và giá trị của một đối tượng bằng cách sử dụng for [[initialExpression]; [conditionExpression]; [incrementExpression]]
statement
75