Loop in macOS not working

Your script is written for zsh but you are executing it with bash.

bash does not support using variables as ranges in brace-expansions.

To resolve this, simply arrange for the script or function be executed in a zsh shell (especially if the script is longer than what you are showing and is using other zsh features). This shell is installed by default on macOS as /bin/zsh. You may add #!/bin/zsh as the first line in the script to have it execute with zsh by default.

See also:

  • Listing numbered files using wildcard sequence with predefined range
  • How can I use $variable in a shell brace expansion of a sequence?
  • Does the shebang determine the shell which runs the script?

The problem here is variable in braces expansion.

Try rewriting it to

for ((i=1;i<=$1;i++))
do
  #your code here
done