Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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