[swift-users] Looping through all values between UInt8.min and UInt8.max

Dmitri Gribenko gribozavr at gmail.com
Fri Apr 8 11:20:15 CDT 2016


On Fri, Apr 8, 2016 at 2:48 AM, tuuranton--- via swift-users
<swift-users at swift.org> wrote:
> print(UInt8.min) //0
>
> print(UInt8.max) //255
>
>
> //Is there an easy way to loop between all values
>
> //between (and including both) UInt8.min and UInt8.max?
>
>
> //This doesn't work.
>
> //Runtime crash because UInt8.max has no successor.
>
> for i in UInt8.min...UInt8.max {
>
>     print(i)
>
> }

Hi,

This works on the
https://github.com/apple/swift/tree/swift-3-indexing-model branch,
which we are about to send a proposal for.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-users mailing list