1

I'm following this: https://tezos.b9lab.com/smartpy/language guide, but it's written for the SmartPy online IDE, I'm trying to do this all in my local dev environment.

PyCharm IDE gives me an "An illegal target for a variable annotation" error when I use the sp.for_. Can anyone help me understand what am I doing wrong?

import smartpy as sp

class Summarise(sp.Contract):
    def __init__(self):
        self.init(storage=0)

    @sp.entry_point(name='sum')
    def sum(self, params):
        sp.for_ i in sp.range(1, params+1):
            pass
2

Found it. The desugared version is

with sp.for_("x", params) as x:
    self.data.result += x

https://smartpy.io/docs/general/control_statements

So the translation for this example is:

with sp.for_("i", sp.range(1, params+1)) as i:
    self.data.storage += i

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.