[swift-users] Looping through all values between UInt8.min and	UInt8.max
    Milos Rankovic 
    milos at milos-and-slavica.net
       
    Fri Apr  8 06:22:48 CDT 2016
    
    
  
Would this work for you?
extension UInt8 {
	var u: UInt { return UInt(self) }
}
for i in UInt8.min.u...UInt8.max.u {
	print(i)
}
milos
> On 8 Apr 2016, at 10:50, tuuranton--- via swift-users <swift-users at swift.org> wrote:
> 
> I forgot to mention that I really would like to have i have type UInt8 within the loop. And since i is UInt8 it makes sense it should be able to take the values UInt8.min and UInt8.max (and all the values between).
> 
> 8. Apr 2016 11:48 by swift-users at swift.org <mailto:swift-users at swift.org>:
> 
> 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)
> 
> }
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160408/32739e86/attachment.html>
    
    
More information about the swift-users
mailing list