Working for-loop and if-statement