2015년 8월 30일 일요일

Javascript loop

Let's see javascript loop statements. Learning test is written using Jasmine. Please refer Jasmine usage which I wrote before if you have interest it.

1. label with continue, break
Javascript can define label. In [line 3],  "firstLoop" label is defined. This is useful when escape nested loop statement. The "break" statement in [line 9] make to escape of the First(for) loop, The second break in [line 13] make to escape loop(while) statement. This is same as in "continue" statements as well.

2. for - in statement
Property name is used in "for - in" statement if the element are Object. If element is array, index is used. In [line 8], p have the attribute name of object and can access the value of property like [line 9]. The [line 22] shows how to use it in Array.

3. for - of statement
The for - of  statement retrieve its element like [line 6] without index.

4. Reference
- MDN - https://developer.mozilla.org/en/docs/Web/JavaScript
- Jasmine - http://jasmine.github.io/2.3/introduction.html

댓글 없음:

댓글 쓰기