Getting loops to work in Starknet's Cairo can be complicated. Currently you need to fiddle around a lot with ap
, fp
and pc
even for mundane computations.
Further, when calling a function within a loop tempvar
will be dereferenced causing the loop to fail. For example the following code will not run:
tempvar iterator=10
tempvar sum=0
loop_start:
let (local a, local b)=div (10, 5)