Ahmed,You severely need to learn indentation:
But, it's not the indentation that's causing your bug. It's the placement of the curly braces.
You have a pair of braces following your if-statement. Everything inside the braces depends on the if-condition. The "beep" code is not inside the braces, so it gets executed every time through the loop, regardless of the if-condition.