At the moment I try to practice my skills in PL/SQL. Like these old Chinese monks I believe that you can only be a master, if you really practice steadily. And while learning I discovered that the LOOP statement in PL/SQL is something really cool, because it would substitute the always famous
while(true):
if expr:
break
do_smth
for implementing the sentinel.
For the sake of this blog I implemented this thing :)
class List:
def __init__(self, node, next): self.node, self.next = node, next
class Block:
def __init__(self, xs): self.xs = xs
def body(self):
print("%d" % self.xs.node)
self.xs = self.xs.next
def cond(self):
return False if self.xs == None else True
class Loop:
def __init__(self, block):
if block.cond():
block.body()
Loop(block)
Loop(Block(List(23, List(42, List(5, None)))))
No comments:
Post a Comment