Array Escape - get out of there
Python, 161 138 bytes

Credits for factorial.



g=lambda x:0**x or x*g(x-1)
f=lambda a,i,n=0,l=[]:(i&lt;0)+(i&gt;=len(a))and n or(0 if i in l else f(a,[a[i],i-a[i]][i and-g(i-1)%i],n+1,l+[i]))


Ideone it!

How it works

Wilson's theorem is used for prime checking.

Loop detection by storing seen indices to an array (l) and checking whether current index is in l.