Your understanding is quite correct.
SmartPy is a Python library, not a Python-inspired language so we use Python everywhere and overload Python's constructions.
This approach is called meta-programming and is extremely important for bigger templates.
Control operators such as if
, for
, while
cannot be overloaded in Python. So we have our own pure-python ones sp.if_
, sp.for_
, etc., and use some syntax transformation, called syntactic sugar, to present them nicely to developers.
Some information is here: https://www.smartpy.io/dev/reference.html#_control_and_syntactic_sugar
Your first error is in the range
, you should use sp.range
since params.op
is a SmartPy expression, not an integer (as Python is telling you).
Then, you will need to you sp.for
as SmartPy will tell you because this needs to be executed on-chain, not at compile time.