begin = end = 0
set up condition
while end is valid:
add item pointed by end
end moves forward
handle the ITEM[end], such as do some bookkeeping
while assersion is disrupted (caused by ITEM[end]):
remove item pointed by begin
begin moves forward
handle the ITEM[begin]
check if assertion is satisfied