Initially $k = 4$, $c = [1, 0, 1, 1]$, $a = 2$, $n = 8$.
Now let's iterate through the function step by step :
$z = 1$ (at the start of do-something)
$i = 0$ (start of external for loop)
In the do loop
$z = 1*1 % 8 = 1$ (non zero value so considered as true and continue)
$c[0] = 1$, so in the if clause, $z = 1*2 \% 8 = 2$
In the do loop
$z = 2*2 \% 8 = 4$ (since now $z = 2$) (non zero value so considered as true and continue)
$c[0] = 1$, so in the if clause, $z = 4*2 \% 8 = 0$
Now no need to check further :
Reason : All the operations that update $Z$ are multiplicative operations and hence the value of $Z$ will never change from $0$.