[Swift-devel] Foreach with floats
Tim Armstrong
tim.g.armstrong at gmail.com
Tue Jul 17 13:44:01 CDT 2012
Something like the following might be the easiest solution:
foreach i in [0:20] {
float j = i * 0.5;
}
I think most languages avoid encouraging use of floats as loop variables
since its fairly easy to run into surprising behaviour with floating point
precision, depending on the way things are implemented.
- Tim
On Tue, Jul 17, 2012 at 11:30 AM, David Kelly <davidk at ci.uchicago.edu>wrote:
> Hello,
>
> Is it possible to use foreach with floating point numbers? Right now I can
> do something like this using ints:
>
> foreach i in [0:10] {
> tracef("i is %i\n", i);
> }
>
> Is it possible to do something similar with floats using some delta value?
> For example, for every value between 0.0 and 10.0 in increments of 0.5?
>
> David
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20120717/74afbef1/attachment.html>
More information about the Swift-devel
mailing list