I need to break a for loop in smartpy, but
break does not work.
Is there any other solution I could use?
Michelson is a functional language.
break statements have no (clean) sense.
LOOP_LEFT is an approximation for
break statements, but in smartpy you can do the following:
import smartpy as sp class MyContract(sp.Contract): def __init__(self, **kargs): self.init(**kargs) @sp.entry_point def ep(self): stop = sp.local("stop", False) sp.while ~ stop.value: sp.if self.data.value > 5: stop.value = True sp.else: self.data.value += 1 @sp.add_test(name = "Example") def test(): scenario = sp.test_scenario() c1 = MyContract(value = 0) scenario += c1 c1.ep()