Thanks for sharing. your intended nesting was not obvious to me as an experienced C, Pascal programmer. You were not helped by C++ not mandating a NEXT command for each FOR let alone the even "more verbose" syntax option for NEXT which allows the compiler to to trap most of these nesting problems especially if it only has the braces to go on.