How to write a do while loop in swift ?

We can use repeat-while which is equivalent to do-while loop in swift. Here the single passthrough will happens first after that condition will be verified

var n = 5
repeat {
    n -= 1
    print("value of n-->", n)// prints 4 to -1
} while n >= 0;

Leave a Comment

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