Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 28, 2015 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/9e80de2a2f89bc25e56c to your computer and use it in GitHub Desktop.
Save chuck0523/9e80de2a2f89bc25e56c to your computer and use it in GitHub Desktop.
# for
# スタンダードな使い方。
sum = 0
for i in [0..9]
sum += i
console.log sum
# 処理文と条件文の順序を逆にすることもできる
sum = 0
sum += i for i in [0..9]
console.log sum
# 2コ飛ばし
sum = 0
sum += i for i in[0..9] by 2
console.log sum
# 配列内包
sum = 0
total = (sum += i for i in [0..9])
console.log total # [0, 1, 3, 6, 10, 15 ....]
# while
i = 0
sum = 0
while i < 10
sum += i
i++
console.log sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment