Skip to content

Instantly share code, notes, and snippets.

@agolajko
agolajko / suez_fp_trick.md
Last active August 8, 2022 22:26
Quick trick for better looping in Cairo

Returning fp for calling functions in Cairo loops

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)