From: Sangil Jung Date: 2012-05-24T17:52:33+09:00 Subject: Re: Simple IO question --90e6ba6153c01d9d8804c0c45f86 Content-Type: text/plain; charset=UTF-8 f.getc will return nil when there is no char more. so, "a = f.getc" is have two roles 1. assign value to a 2. check end of file 2012/5/24 Kaye Ng > This prints every fifth character in a file: > > f = File.new("test.txt", "r") > while a = f.getc > puts a.chr > f.seek(5, IO::SEEK_CUR) > end > > I don't quite get the meaning of it. Is it like, "while the variable > 'a' has a value or contains something, it should be printed onto the > screen"? > > Why is it not "while a == f.getc" ? ( == instead of = ) > > What does getc here mean anyway? I know it reads a single character, > correct? > > Thank you guys! > > -- > Posted via http://www.ruby-forum.com/. > > -- ---------------------------------------- Sangil Jung. +82.10.6402-4639 http://humbroll.com --90e6ba6153c01d9d8804c0c45f86 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
f.getc will return nil when there is no char more.=C2=A0
so,= =C2=A0
"a =3D f.getc" is have two roles
1. as= sign value to a=C2=A0
2. check end of file=C2=A0


2012/5/24 Kaye Ng <lists@ruby-forum.com>
This prints every fifth character in a file:

f =3D File.new("test.txt", "r")
while a =3D f.getc
=C2=A0puts a.chr
=C2=A0f.seek(5, IO::SEEK_CUR)
end

I don't quite get the meaning of it. =C2=A0Is it like, "while the = variable
'a' has a value or contains something, it should be printed onto th= e
screen"?

Why is it not "while a =3D=3D f.getc" ? ( =3D=3D instead of =3D )=

What does getc here mean anyway? I know it reads a single character,
correct?

Thank you guys!

--
Posted via http://= www.ruby-forum.com/.




-- ----------------------------------------
Sangil Jung.

+82.10.64= 02-4639
http://humbro= ll.com
--90e6ba6153c01d9d8804c0c45f86--