update code for loop and if-then-else