Here's the question you clicked on:
minimallinux
How does iterMul work anyone ? def iterMul(a, b): result = 0 while b > 0: result += a b -= 1 return result It returns the product but how ?
The loop is based on b and there loops b many times. Inside the loop it simply adds a so say you have a of 3 and b of 4. If you add 3 for times you get 3+3+3+3 which is the same as 3*4.
as long as b is greater than 0 (while b > 0) it's adding the value of "a" to the local variable "result" (result += a) and also subtracting "b" by 1 (b -= 1), so be goes towards 0, and for each iteration another "a" is added to "result"! , we'll have "b" iterations (for each positive "b") and it makes b*a