Stride in Swift using for loop

Updated 9 June 2017

Save

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:-

 

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home