We can trace the execution of DOSOMETHING(c, a, n) with k=4, c=⟨1,0,1,1⟩, a=2, and n=8:
Iteration i=0 (c[0]=1):
z←z2mod8=12mod8=1
Since c[0]=1: z←(z×a)mod8=(1×2)mod8=2
Iteration i=1 (c[1]=0):
z←z2mod8=22mod8=4
Since c[1]=0, the if condition is false.
Iteration i=2 (c[2]=1):
z←z2mod8=42mod8=16mod8=0
Since c[2]=1: z←(z×a)mod8=(0×2)mod8=0
Iteration i=3 (c[3]=1):
z←z2mod8=02mod8=0
Since c[3]=1: z←(z×a)mod8=(0×2)mod8=0
After all iterations, the returned value of z is 0.