Swift - Write program to use a while loop to calculate the number of times the number is divisible by 2

Requirements

use a loop to calculate the number of times the number is divisible by 2

keep dividing the number as long as the number is greater than 1.

Demo

P:The preceding problem could be solved using the following code snippet:

Demo

var counter = 0
var num = 32//from w  w  w.  j a  v a2 s  . c  om
while num > 1 {
   counter++
   num /= 2
}
print("The number is \(counter) times divisible by 2")