@echo off
setlocal enabledelayedexpansion
if "%~1"=="" (
echo(
) else if "%~1"=="/?" (
echo BEEP [/? | LOOP [TIMES]]
echo THIS COMMAND IS USED TO BEEP.
) else if /i "%~1"=="loop" (
set /a "number2=%~2"
for /l %%i in (1,1,!number2!) do echo(
) else (
echo INPUT "BEEP /?" TO SEE HELP.
)
Your problem was delayed expansion. All variable reads inside a block of code (code inside parenthesis) gets replaced with the value in the variable before the block starts to execute. If a variable is changed inside the block, that new value can not be retrieved, as all reads to variables were replaced with values. To solve, enable delayed expansion and, in variables where delayed read is needed, change %var%
sintax with !var!
to indicate the parser to delay the read until the time of execution.