Ruby
迴圈:你就跑個 5 圈吧!
迭代:你把這 5 個元素全部都看過一次吧!
Ruby 裡沒有一般的那種 for 迴圈:
for (var i = 0; i < 10; i++) {
console.log(i)
}
names = ["eddie", "joanne", "john", "sherly"]
for name in names
puts name
end
x = 0
while x < 10
puts x
x += 1 # 小心不要變成無窮迴圈
end
until = while not
while = until not
x = 0
until x >= 10
puts x
x += 1
end
i = 0
loop do
puts i
i += 1
break if i > 10
end
5.times do
puts "hello, ruby"
end
1.upto(10) do |i|
puts "hello, ruby #{i}"
end
10.downto(1) do |i|
puts "hello, ruby #{i}"
end
names = ["eddie", "joanne", "john", "sherly"]
names.each do |name|
puts name
end
# 外鄉人
names = ["eddie", "joanne", "john", "sherly"]
x = 0
names.each do |name|
puts "#{x} #{name}"
x += 1
end
names = ["eddie", "joanne", "john", "sherly"]
names.each.with_index do |name, x|
puts "#{x} #{name}"
end
Familiarity with Rakuten Travel QA Workflow (Hands-On Experience)
Dec 4, 2024A compilation of essential vocabulary gathered during my internship at Rakuten, with a sum of 94.
Mar 21, 2024在 Ruby 裡,幾乎什麼東西都是物件
Mar 1, 2024create web applications in Ruby
Mar 1, 2024or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up