1Return statement. The return statement stops execution and returns to the calling function. When a return statement is executed, the function is terminated immediately at that point, regardless of whether it's in the middle of a loop, etc.
2
1void printChars(char c, int count) {
2 for (int i=0; i<count; i++) {
3 cout << c;
4 }//end for
5
6 return; // Optional because it's a void function
7}//end printChars
8
1// Multiple return statements often increase complexity.
2int max(int a, int b) {
3 if (a > b) {
4 return a;
5 } else {
6 return b;
7 }
8}//end max
9
1// Single return at end often improves readability.
2int max(int a, int b) {
3 int maxval;
4 if (a > b) {
5 maxval = a;
6 } else {
7 maxval = b;
8 }
9 return maxval;
10}//end max
11