Because then is neither a command nor a shell builtin, but actually a part of the if syntax. From man bash:
if list; then list; [ elif list; then list; ] ... [ else list; ] fi The if list is executed. If its exit status is zero, the then list is executed. Otherwise, each elif list is executed in turn, and if its exit status is zero, the corresponding then list is executed and the command completes. Otherwise, the else list is executed, if present. The exit status is the exit sta‐ tus of the last command executed, or zero if no condition tested true.
So this:
if [ $table = "Session" ]; then continue; fi
works because both [ $table = "Session" ] and continue are commands that can stand alone; they make up the respective list part of the if command. Just paste those into an interactive shell and you will see that they won't cause any syntax errors:
martin@martin:~$ export table=test martin@martin:~$ [ $table = "Session" ] martin@martin:~$ continue bash: continue: only meaningful in a `for', `while', or `until' loop
On the other hand, then is not a real command that can stand on its own:
martin@martin:~$ then bash: syntax error near unexpected token `then'
So in the first two examples, you're using if just like the man page describes it:
if list; then list; fi
But if you put a ; behind then, bash will see this as a syntax error. Admittedly, shell syntax can seem quite confusing sometimes, especially when you're just getting into it. I remember being very confused about the fact that it requires spaces around [ and ], but once you realize that [ is actually a command or shell builtin, it's comprehensible. :)
;with anewlineand it works. Otoh, omit the line withcontinueand you get the error. Read the source, Ben.