tailieunhanh - Học JavaScript qua ví dụ part 15

Loops Các vòng được sử dụng để thực thi một đoạn mã liên tục cho đến khi tình trạng một số được đáp ứng. vòng lặp cơ bản của JavaScript xây dựng được • khi • cho • làm / trong khi Trong khi Loop Các báo cáo trong khi thực hiện khối tuyên bố của mình miễn là các biểu hiện sau khi các đánh giá cho đúng, đó là, nonnull, khác không, nonfalse. Nếu tình trạng này không bao giờ thay đổi và là sự thật, vòng lặp sẽ lặp đi lặp lại mãi mãi (vòng lặp vô hạn). Nếu điều. | Loops 131 EXPLANATION continued 6 The default statements are executed if none of the cases are matched. 7 This final break statement is not necessary but is good practice in case you should decide to replace the default with an additional case label. 8 The final curly brace ends the switch statement. Figure displays examples of the output. The Switch Statement - Mozilla Firefox File Edit View History Bookmarks Tools Help c X I a í I I file C wamp www 012 Q Comparing . Conditional. 1 Conditional. javascript JavaScript Application Business hours Monday through Thursday are from 9am to 10pm X OK Figure A random number between 1 and 7 determines which case is matched and executed. Loops Loops are used to execute a segment of code repeatedly until some condition is met. JavaScript s basic looping constructs are while for do while The while Loop The while statement executes its statement block as long as the expression after the while evaluates to true that is nonnull nonzero nonfalse. If the condition never changes and is true the loop will iterate forever infinite loop . If the condition is false control goes to the statement right after the closing curly brace of the loop s statement block. The break and continue functions are used for loop control. From the Library of 132 Chapter 6 Under Certain Conditions FORMAT while condition statements increment decrement counter EXAMPLE html head title Looping Constructs title head body h2 While Loop h2 font size 2 1 script type text javascript 2 var i 0 Initialize loop counter 3 while i 10 Test 4 i 5 i Increment the counter 6 End of loop block 7 script font body html EXPLANATION 1 The JavaScript program starts here. 2 The variable i is initialized to 0. 3 The expression after the while is tested. If i is less than 10 the block in curly braces is entered and its statements are executed. If the expression evaluates to false . i is not less than 10 the loop .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG