#!/bin/sh

#   Yes, you can execute this whole script for demonstration.  You may
#   also want to try giving it an argument or two (or none) to see how
#   that behaves also.

#   Of course you also remember comments, the here document, and the :
#   command, right? :-)  Okay, so I effectively (but not literally)
#   comment out the part between the pairs of __EOT__ without having to
#   individually comment out most or all the lines in the section.

>>/dev/null 2>&1 : << \__EOT__

    #   for syntax:

for name in word ...

   #name is a parameter/variable
   #----

    #    in word ... portion is optional, defaults to in "$@"
    #    -----------                                  +++++++

    #       word ... is 1 or more words (can be results from
    #       --------    various forms of substitution) which name is
    #                   then set to in turn for each iteration of the
    #                   loop

    #   need a newline or semicolon before do
do
    #   need whitespace (one or more blanks, tabs, and/or newlines)
    #   between do and list (so do can be recognized as keyword and not
    #   part of some other word)

        list

    #   need a newline or semicolon between list and done
done

__EOT__

# Typical fairly readable use in scripts:
for myvariable in A B C
do
	echo "$myvariable"
done

# somewhat less readable version with minimum whitespace and no semicolons:
for myvariable in A B C
do echo "$myvariable"
done

# without newlines:
for myvariable in A B C; do echo "$myvariable"; done

# somewhat less readable version with minimum whitespace and no newlines
# within the command:
for myvariable in A B C;do echo "$myvariable";done

# Two examples defaulting to using "$@" (which evaluates to all the
# positional arguments, quoted):
for myvariable
do
	echo "$myvariable"
done
for myvariable; do echo "$myvariable"; done

# list can be quite non-trivial (remember definition of list), teensy
# example where list is another for command:
for letter in a b c
do
	for digit in 1 2 3
	do
		echo "$letter$digit"
	done
done
