sval: fix a bug in handling for loops that count downwards