[trunk] simplify code using for loop
[trunk] add a sentinel in debug code
[trunk] improve command line parser syntax checking
[trunk] add issue 46 to the test suite
Fixes issue 46