Nested if statement, use "break" to break out of if statment only

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I want to break out of an if statement if one of the nested if statements is true. When I use the "break" it breaks me out of the if statement and the switch statement. How do I break out of the if statement only? Here is the
code.
<pre class="prettyprint void INFORCE::Read_VUL_Funds(string file_loc,string file_nm)
{
string x;
x = file_loc + file_nm;
FILE *infile;
errno_t e = fopen_s( &infile, x.c_str(), "r" );
if(infile == NULL)
{ LogFile<<"Error - unsuccessful open"<<file_loc<<", "<<file_nm<<endl; exit(0);}
double temp=0;
int column = 0, row = 0, pol_count = 1,record=0;
int i = 0;
char chrX[5000];
int p;
int num1 = 0, num2 = 0;
//double y1,y2,y3;
vector<double>y1(10);
vector<double>y2(10);
vector<double>y3(10);
//string x1,x2,x3,x4;
vector<string>x1(10);
vector<string>x2(10);
vector<string>x3(10);
vector<string>x4(10);
//vector<double> SA1(2000);
// vector<double> SA2(2000);
// vector<double> SA3(2000);
fgets(chrX,sizeof(chrX)-1,infile); //Skip past header
while(fgets(chrX,sizeof(chrX)-1,infile))
{
char *ptr = strtok(chrX,",nr");
column = 0; //Reset Column Count
row++;
record++;
while(ptr)
{
switch(column)
{
case 0: //KEYFIELD - policy number
sscanf(ptr,"%d",&p);
//Check if policy number changed
if(record == 1 || record ==2)
{num1 = p; num2 = p;}
else
{
if ( record % 2== 0 ) num1 = p; else num2 = p;
if(num1 != num2) {pol_count++; row = 1;}
}
break;
case 1: //GROUP - not used
x1[row] = ptr;
break;
case 2: //ACCOUNT: "General", "Separate"
x2[row] = ptr;
break;
case 3: //FV_BASIS: "Current", "Secondary Guarantee"
x3[row] = ptr;
break;
case 4://FUND_CD: FIXED, AGRSVNASD, CORPBOND, DVRSSP500, INTLEAFE, MDMRUSS2K, MONMKT
x4[row] = ptr;
break;
case 5:
sscanf(ptr,"%lf",&y1[row]);
//Populate:
//a.) General Account
//b.) Secondary Guarantee
//c.) Seperate Account
if(x2[row]=="Separate" && x3[row] == "Current")
{
if(x4[r ow]=="AGRSVNASD") {AGRSVNASD[pol_count] = y1[row]; break;}
if(x4[row]=="CORPBOND") CORPBOND[pol_count] = y1[row];
i f(x4[row]=="DVRSSP500") DVRSSP500[pol_count] = y1[row];
if(x4[row]=="INTLEAFE") INTLEAFE[pol_count] = y1[row];
if(x4[row]=="MDMRUSS2K") MDMRUSS2K[pol_count] = y1[row];
if(x4[row]=="MONMKT") MONMKT[pol_count] = y1[row];

}//End If
if(x2[row]=="General" && x3[row] == "Current") FIXED[pol_count] = y1[row]; //General Account

break;
case 6:
sscanf(ptr,"%lf",&y2[row]);
break;
case 7:
sscanf(ptr,"%lf",&y3[row]);
break;
}//End Column Switch
++column;
ptr = strtok(NULL,",nr");
}//End While Loop
}//End If Loop
fclose(infile);
}[/code]
<br/>

View the full article
 
Back
Top