|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi,
Here is a method inside a string returning function: Code:
string computeSin(argument 1, argument 2)
{
if ( strcmp(icmop->icmo_addl_infop->retval_str, "USA") == 0 )
{
string newIsin = (string)"US" + icmop->icmo_tranche_cusips[trancheNum];
int d1, d2, sum, multiply, i;
for (sum = 0, multiply = 1, i = 10; i > -1; --i) {
switch (i) {
case 0:
case 1:
if (isupper(newIsin[i]))
d1 = newIsin[i] - 'A' + 10;
else
return 0;
break;
default:
if (isupper(newIsin[i]))
d1 = newIsin[i] - 'A' + 10;
else if (isdigit(newIsin[i]))
d1 = newIsin[i] - '0';
else
return 0;
break;
}
if (d1 < 10) {
d1 *= (multiply ? 2 : 1);
multiply = !multiply;
} else {
d2 = d1 / 10;
d1 %= 10;
d1 *= (multiply ? 2 : 1);
d2 *= (multiply ? 1 : 2);
sum += (d2 % 10) + (d2 / 10);
}
sum += (d1 % 10) + (d1 / 10);
}
sum %= 10;
sum = 10 - sum;
sum %= 10;
std::stringstream isinSs;
isinSs << newIsin << sum;
const std::string &checkedIsin = isinSs.str();
return checkedIsin;
}
return argument 2;
}//end of string method
If in the switch statement section of this code I reach return 0 (appears twice: once in case 1 and other in default), would I be taken out of this computeSin method or would I keep looping till the for loop finishes? Normally, a return statement takes you out of a function but in this case if I reach return 0 which is in a switch statement that will keep running till the for loop ends, would I exit the whole method? Thanks. Last edited by ozyabm; 06-30-2008 at 02:06 PM. |
| Sponsored Links |
|
|
|
|||
|
Yes, it will. If you want to continue looping, use the continue statement.
|
![]() |
| Tags |
| return, string function, switch |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SecurityAudit | vinay | Visual Basic Programming | 27 | 01-07-2008 12:14 PM |
| displaying mysql data into jtextfield.Pls help | iz.ziffa | Java Help | 1 | 05-31-2007 10:58 AM |
| Xav | ........ | 1024.41 |
| MeTh0Dz|Reb0rn | ........ | 974.08 |
| morefood2001 | ........ | 850.04 |
| John | ........ | 841.93 |
| WingedPanther | ........ | 661.52 |
| marwex89 | ........ | 575.59 |
| Brandon W | ........ | 447.33 |
| chili5 | ........ | 292.12 |
| orjan | ........ | 187.41 |
| Steve.L | ........ | 181.88 |
Goal: 100,000 Posts
Complete: 79%