I'd have to see a script to comment on your problems, but the script below works as you describe.
Code:
#!/bin/sh
COUNT=0
while [ $COUNT -lt 5 ]; do
echo $COUNT
COUNT=`expr $COUNT + 1`
done
echo "Fishished: $COUNT"
Code:
# ./loop.sh
0
1
2
3
4
Fishished: 5