小编Ris*_*era的帖子

关于除非循环的 Ruby I/O 编程

作为来自http://ruby.bastardsbook.com/chapters/io/的教程

file = File.open("sample.txt", 'r')
while !file.eof?
   line = file.readline
   puts line
end
Run Code Online (Sandbox Code Playgroud)

这种方法把每一行,但是当我更换

while !file.eof?  
Run Code Online (Sandbox Code Playgroud)

unless file.eof?
Run Code Online (Sandbox Code Playgroud)

循环只运行一次,为什么?

ruby io

1
推荐指数
1
解决办法
54
查看次数

标签 统计

io ×1

ruby ×1