4

Closed

SA1500 Do-While Loop

description

SA 1500 prevents the normal construction of a Do-While loop:
Do
{
// multiple lines of code
} While (condition);
Closed Aug 1, 2013 at 2:41 PM by andyr

comments

andyr wrote Aug 1, 2013 at 2:40 PM

This is correct.
It should be:

do
{
// multiple lines of code

}
while (condition)

With the while on a separate line to the curly bracket

jayj wrote Jun 20 at 5:30 PM

The 'while' condition should be placed on the same line as the closing brace - to strongly couple the 'while' condition to the correct code block. This is because 'while' is both a pre- and post-block keyword (while{} and do{}while)

Consider the following dirty code:
   ...
   ...
   // multiple lines of code
}
while (condition)
{
   // multiple lines of code
}
You cannot tell what the author's intent is; without spending time scrolling up & down trying to match up code blocks.