C/C++ Best Practices #1

This course describes all Visa's C/C++ best practices.  Each best practice includes a description, the reasoning behind the best practice chosen, one or more examples, and concludes with an opportunity for you to test your understanding.

#1 loops should have simple constructs with only one terminating condition

Why?  All loops should have simple constructs with only one terminating condition in order to avoid the ambiguity that can occur when using AND / OR constructs with multiple terminating conditions.

Example #1:   for(int maxStates = 0; maxStates < NUMBER_OF_STATES; maxStates++)

Example #2: do{  ....   }while(rc=0);

Example #3 if there are multiple ways to exit a loop, use continue rather than a flag

How many terminating conditions should be coded on looping constructs?

How many terminating conditions should be coded for a loop construct?

  • 1
  • 2
  • 3
  • it depends

Which of these loop constructs follows Visa's C/C++ best practices guideline?

  • for( int a=0,b=0; a<b
  • Put your answer option here