How to add a Y/N option?

I want to be able to add to any script that gives the option to continue or not, after the the first loop thru and to keep giving you the option after the user answers "Y" then does their thing then gives that option again once done. I've been seeing examples online on how to do it, but not for it to keep looping through when you keep saying "Y".

Perhaps you want something like:

#!/bin/ksh
printf 'Do you want to start looping (Y<enter> to continue; anything else to stop)?: '
read response
while [ "$response" = "Y" ]
do	printf '\nOK\n'
	# Do whatever you want to do here...
	printf 'Do you want to go again (Y<enter> to continue; anything else to stop)?: '
	read response
done
echo 'Goodbye.'

The above should work with any POSIX-conforming shell. Some shells (including ksh provide shortcuts to combine the read and printf command pairs shown in this script into a single read call, but those extensions vary from shell to shell and shell release to shell release.

Here is two examples. Also

read -p

is usable.

Using read -n 1.

#!/bin/ksh
# bash/ksh93/zsh/... but not dash (=posix)

# if read key ENTER, bash return newline and ksh return carriage return
cr=$'\r'  # ENTER key ksh
while printf "Continue:Y\b"
      read -n 1 response
      printf "\r                  \n"
      case "$response" in
                $cr|Y|y|"") response="Y" ;; # default = ENTER
                n|N) reponse="N" ;;
                *) response="N" ;;
      esac
      [ "$response" = "Y" ]
do
                echo "Do ..."
                date
                echo "..."
done

echo 'Goodbye.'

Using dd = take dump from stdin, 1 char.

# keypressed, read 1 char from stdin using dd
# works using any sh-shell
readkbd() {
  stty -icanon -echo
  dd bs=1 count=1 2>/dev/null
  stty icanon echo
}

while printf "Continue:Y\b"
      response=$(readkbd)
      printf "\r                  \n"
      case "$response" in
                Y|y|"") response="Y" ;; # default = ENTER
                n|N) reponse="N" ;;
                *) response="N" ;;
      esac
      [ "$response" = "Y" ]
do
                echo "Do ..."
                date
                echo "..."
done

echo 'Goodbye.'