a good way of doing the loop would be to make a for loop. I'm still lost as to how/why it would constantly be resizing it self for the need of the loop. Can you elaborate more?
function resizeToContent(){
var x =0;
var y =dynamIframe.document.body.scrollHeight;
while (x < y){x+=1;}
this.document.getElementById("dynamIframe").style.height=x+10}