|
||||||
| 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 |
|
|
|
|||||
|
I believe Return 0 will exit the function completely.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||
|
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 |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| gaylo565 | ........ | 18.00000 |
| WingedPanther | ........ | 15.00000 |
| |pH| | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 66%