It executes the body of the loop once for each directory name. There are two ways to introduce long string literals into shell scripts. The use of quotes around the end delimiter is a bit of magic preventing variable and command substitution in the body of the here document. Calling wait without an argument waits for all background jobs. The separate - tells the set command that there are no more options, and all following words are arguments.
Some options are simple flags.
One should be able to give options in any order. Each arm of the case statement consumes exactly the elements of the argument that it has processed. Some shell scripts use temporary files. Such scripts should ensure that these get cleaned up on exit and if the shell script is interrupted. After you execute set -x, sh will print each command just before it is executed.