From: Seebs Date: 2010-01-10T07:15:05+09:00 Subject: Re: Decimal in for loop? On 2010-01-09, Nathan Oyama wrote: > Hi, I have a quick question: How can I increase a valuable by a certain > decimal (not an integer) in a for loop? > > For example, in C, > > for( i = 0; i < 0.5; i += 0.1 ) > printf( "%f ", i ); > > the code above returns > > 0.0 0.1 0.2 0.3 0.4 No, it doesn't. Nor does it print that (remember, "for" loops have no "return value" in C). It might print "0.000000 0.100000 ...". :) > ps I looked in several Ruby tutorials, but couldn't find any example > using a decimal. . . Should I use another loop syntax like 'loop' or > 'while/until'? Usually, this is not the right way to do it, but you might be able to do something like this using one of the upto-like methods, I think it might be called "step". -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!