1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Use "index" for index variable in for loop

This confused me every time I Ctrl+F'ed the home page for "index" and only got
this cryptic statement:

"Comprehensions replace (and compile into) for loops, with optional guard clauses
and the value of the current array index."

Now I can see how the index is used in the code.
This commit is contained in:
Jo Liss 2011-11-23 16:24:36 +01:00
parent 30614c5721
commit 57e109ff11
2 changed files with 5 additions and 5 deletions

View file

@ -3,7 +3,7 @@ eat food for food in ['toast', 'cheese', 'wine']
# Fine dining
courses = ['salad', 'entree', 'dessert']
menu course + 1, dish for dish, course in courses
menu index + 1, dish for dish, index in courses
# Health conscious meal
foods = ['broccoli', 'spinach', 'chocolate']

View file

@ -1,4 +1,4 @@
var course, courses, dish, food, foods, _i, _j, _len, _len2, _len3, _ref;
var courses, dish, food, foods, index, _i, _j, _len, _len2, _len3, _ref;
_ref = ['toast', 'cheese', 'wine'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@ -8,9 +8,9 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
courses = ['salad', 'entree', 'dessert'];
for (course = 0, _len2 = courses.length; course < _len2; course++) {
dish = courses[course];
menu(course + 1, dish);
for (index = 0, _len2 = courses.length; index < _len2; index++) {
dish = courses[index];
menu(index + 1, dish);
}
foods = ['broccoli', 'spinach', 'chocolate'];