One way is using eval:
for i in $( eval echo {0..$length} )
do
echo "do something right $i"
done
Note what happens when you set length=;ls or length=; rm * (don't try the latter though).
safely, using seq:
for i in $( seq 0 $length )
do
echo "do something right $i"
done
or you can use the c-style for loop, which is also safe:
for (( i = 0; i <= $length; i++ ))
do
echo "do something right $i"
done