created a for loop and if statement

used variables j and m