Here is a section of code that was written long ago using the WHILE statement in ADN.
Maybe this will give you an idea of how to improve your code:
Within this code snippet the While statement is used more than once.
// -------------------------
public behavior service( tSubsystemName ) {
didForward = false;
integer mode = transactionMode();
beginService();
if ( localTime <= 0 ) {
call serviceExecute();
}
else {
if (( mode == LOCAL ) || ( mode == PARALLEL_LOCAL )) {
remLocalTime = localTime;
}
else {
qTime = simGetTime() - fQueueStartTime;
remLocalTime = localTime - qTime; // Remaining local time
}
if ( remLocalTime <= 0.0 ) {
call serviceExecute();
}
else {
join {
thread { Delay remLocalTime; }
thread { call serviceExecute(); }
} // End join
} // End if
} // End if
integer ccInt;
integer ccLoop;
real ccRem;
real prob;
ses_ResourcePoolIF ptPool;
if ( count1 < 0.0 ) {
ccInt = 10000;
}
else {
if ( count1 < 1.0 ) {
print "*** Background_phgp0137_UnCoupled parallel thread count =", count1, "; must be >= 1.0";
print "*** Background_phgp0137_UnCoupled.count1 set to 1.0";
count1 = 1.0;
}
ccInt = Integer( count1 );
ccRem = count1 - ccInt;
if ( ccRem > 0.0 ) {
prob = Uniform( 0.0, 1.0 );
if ( prob <= ccRem ) {
ccInt = ccInt + 1;
}
}
}
ptPool = ses_ResourcePoolFactory.create( "Background_phgp0137_UnCoupled_CalleeThreadPool",
ccInt, ses_ResourcePoolFactory.DISCIPLINE_FIFO,
ses_ResourcePoolFactory.POOLTYPE_RESOURCE ,
ses_ResourcePoolFactory.POOLSTATS_NONE );
// Begin Parallel group
join {
thread {
integer mode2 = ses_Transaction.PARALLEL_LOCAL;
integer ccInt2;
integer ccLoop2;
real ccRem2;
real ccProb2;
ccInt2 = Integer( count2 );
ccLoop2 = ccInt2;
while ( ccLoop2 > 0 ) {
call ptPool.allocate( 1 );
call Background_phgp0137_CPUtime.initiate( this, mode2, null );
tmp = ptPool.free( 1 );
ccLoop2 = ccLoop2 - 1;
}
ccRem2 = count2 - ccInt2;
if ( ccRem2 > 0.0 ) {
ccProb2 = Uniform( 0.0, 1.0 );
if ( ccProb2 <= ccRem2 ) {
call ptPool.allocate( 1 );
call Background_phgp0137_CPUtime.initiate( this, mode2, null );
tmp = ptPool.free( 1 );
}
}
} // End thread
thread {
integer mode3 = ses_Transaction.PARALLEL_LOCAL;
integer ccInt3;
integer ccLoop3;
real ccRem3;
real ccProb3;
ccInt3 = Integer( count3 );
ccLoop3 = ccInt3;
while ( ccLoop3 > 0 ) {
call ptPool.allocate( 1 );
call Background_phgp0137_DiskIO.initiate( this, mode3, null );
tmp = ptPool.free( 1 );
ccLoop3 = ccLoop3 - 1;
}
ccRem3 = count3 - ccInt3;
if ( ccRem3 > 0.0 ) {
ccProb3 = Uniform( 0.0, 1.0 );
if ( ccProb3 <= ccRem3 ) {
call ptPool.allocate( 1 );
call Background_phgp0137_DiskIO.initiate( this, mode3, null );
tmp = ptPool.free( 1 );
}
}
} // End thread
} // end join
endService( msgReplySize );
mode = transactionMode();
if ( (mode == SEQUENTIAL_ASYNC) || (mode == PARALLEL_ASYNC) ||
( (mode == FORWARD) && (didForward || !(isSynchronousThread())) ) ) {
endTransaction();
}
} // end service