One problem is the if statement on line 6:
The first time entering the loop, next is equal to 0, so we go to line #5
After the above executes, next is now equal to 2
Your line 7 if evaluates to 0 (zero) which is a falsely value, so line 8 is skipped and the while asks if next is less than num. Since 2 is less than num (10) in your example we go through the same thing again. Since there are only 2 items in arr, next is going to keep being 2 forever (hence the infinite loop you have).
If you get stuck or do not understand what I have written here, please reply back and I will try to guide you in the right direction with small hints.