is there anyway to increment exponentially in swift?

前端 未结 4 1112
悲哀的现实
悲哀的现实 2021-01-27 05:08

I am trying to write a for loop, where I have to increment exponentially. I am using stride function but it won\'t work. Here\'s c++ code, I am trying to write a sw

4条回答
  •  自闭症患者
    2021-01-27 05:29

    There is no for loop in Swift, but you can achieve the same result with basic while loop

    var m = 1                // initializer
    while m <= high - low {  // condition
        ...
        m *= 2               // iterator
    }
    

提交回复
热议问题