我想在一个循环中连接一个字符串,就像这样,但是在 Ruby 中:
$fizz = file_get_contents($_SERVER['argv'][1]);
$output = "";
for($i=1;$i<=$fizz;$i++) {
if($i % 3 == 0 && !($i % 5 ==0)) {
$output .= "fizz\n";
}
else if($i % 5 == 0 && !($i % 3 ==0)) {
$output .= "buzz\n";
}
else if($i % 3 == 0 && $i % 5 == 0) {
$output .= "FizzBuzz\n";
}
}
print $output;
?>
我也有兴趣找出“.=”类型运算符的名称,以便我可以通过 Google 更好地搜索这些东西。
使用 Ruby 1.8.6。
最佳答案
关于php - 等同于 PHP 的 .= 运算符的 ruby?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6191986/