Start a Project

Stride in Swift using for loop

Stride in Swift

Using Stride in swift is like using for loop in C – language and in C – the language you use for loop like:-

And in Swift, you can use only for each loop example:-

When you want to increment value of like   i= i+2 or i = i +3  so it’s not possible directly to increment the value of i in swift for each loop so you have to apply your own logic to increment the value of i, like in C language. By stride method you can increment value stride contains two methods : –

Using   stride(from:to:by:) it will not include the value of last value that you will give to:  field  and set by: field value that is incremented value example:-

Using  stride(from:through:by:) it will include the value of last value that you will give through:  field  and set by: field value that is incremented value example:-

 

 

Exit mobile version