C++

int digits = (int) log10(num) + 1; for (int i = 0; i < digits; i++) { ... }Inside the loop, you can extract the least significant digit using the modulus operator, and prepare the number for the next time round the loop by dividing it by ten.

Give it a try, it's quick, efficient, and easy to code!