Code:

done =0; n = presentvalue = 0;
// Main simulation loop.
while(!done) {
while(n<100000){
setFlagA=setFlagBBB=setFlagBB=setFlagB=setFlagC=0;
// Initialize credit rating.
i = credit0;
// Determine the month k of the bond's last cash flow. Initialize to 0.
k = 0;
// Evolve the credit rating month by month to the bond's maturity.
while (1) {
// Current credit rating is "i", updated rating will be "j".
// Determine new credit rating via inverse transform.
U = MTUniform (0);
int jmin;
jmin = (i >= 1 ? i-1 : 0);
for (j = jmin; j <= 8; j++) {
if (U <= P[i][j]) {
break;
}
}
// If not yet defaulted, issuer survives one more month.
if (j != 8) {
k ++;
}
if (k==maturity){
n++;
break;
}
if (j == 8) {
presentvalue=(20000000 * exp(-r*k*1/12))+presentvalue;
n++;
break;
while (i>j){
if (j==3 && setFlagA==0){
presentvalue+=20000000 * exp(-r*k*1/12);
setFlagA==1;
break;
}
else if (j==4 && setFlagBBB==0){
presentvalue+= 20000000 * exp(-r*k*1/12);
setFlagBBB==1;
break;
}
else if(j==5 && setFlagBB==0){
presentvalue+= 20000000 * exp(-r*k*1/12);
setFlagBB==1;
break;
}
else if(j==6 && setFlagB==0){
presentvalue+= 20000000 * exp(-r*k*1/12);
setFlagB==1;
break;
}
else if (j==7 && setFlagC==0){
presentvalue+= 20000000 * exp(-r*k*1/12);;
setFlagC==1;
break;
}
}
// Update the issuer's current credit rating.
i = j;
}
}
}
printf("The present value is %8.3f\n",presentvalue/n);
}
if (presentvalue>0) {
done = 1;
}
// Pause before closing up window.
Exit ();
}

The code is meant to sum the present value of a credit swap payout by using RNGs. So, I am running a loop to see if the bond rating dropped to a new low and if it does I sum the PV. But my output is 0.0000, and it constantly repeats without stopping.