break , continue, how to understand

J

Jianli Shen

const DInst *stopAtDst = 0;

while (dinst->hasPending()) {

if (stopAtDst == dinst->getFirstPending())
break; ///////break? break? break? is this break outof the whole
while loop and never in the loop again???????????????????????

DInst *dstReady = dinst->getNextPending();

if (!dstReady->isIssued()) {

// Accross processor dependence
if (dstReady->hasDepsAtRetire())
dstReady->clearDepsAtRetire();

continue; //////continue?? continue?? continu?? is this continue
means finish this iteration of the loop and continue working on the next
iteration of the loop if any
}
if (dstReady->isExecuted()) {
if (!dstReady->hasDeps())
dstReady->scrap(); //dInstPool.in(this)
continue;
}

if (dstReady->hasDepsAtRetire() && dinst->getInst()->isStore()) {
dosomething;
}
}
 
R

rahul.batra

const DInst *stopAtDst = 0;
while (dinst->hasPending()) {

if (stopAtDst == dinst->getFirstPending())
break; ///////break? break? break? is this break outof the
whole
while loop and never in the loop again???????????????????????


Yes you are right, here! :)

DInst *dstReady = dinst->getNextPending();

if (!dstReady->isIssued()) {

// Accross processor dependence
if (dstReady->hasDepsAtRetire())
dstReady->clearDepsAtRetire();

continue; //////continue?? continue?? continu?? is this
continue
means finish this iteration of the loop and continue working on the
next
iteration of the loop if any


No, you are wrong here!!
This 'continue;' will NOT finish this current iteration. Instead, this
continue statement will force the control to jump directly to the
'while (dinst->hasPending())' again (i.e. to the next iteration,
WITHOUT finishing the current iteration).
Now, whether this iteration (i.e. the next iteration) is executed or
not depends upon wheteher 'dinst->hasPending()' is true or false.

Maybe you'll find these links helpful:
http://msdn.microsoft.com/library/en-us/vccelng/htm/statem_16.asp?frame=true
http://msdn.microsoft.com/library/en-us/vccelng/htm/statem_17.asp?frame=true
 
M

Malte Starostik


What they say about break and continue seems right. OTOH I would
definately refrain from recommending those links because of these:
* The heading "C/C++ Language Reference" - there is no C/C++ language.
There is C and there is C++.
* The examples are written in C (#include <stdio.h>, printf(), NULL
instead of 0)
* The example for continue uses a platform-specific API (_getche())
* The examples are neither valid in C nor in C++ (void main())

Cheers,
Malte
 
R

rahul.batra

Hi Malte,

I learnt a nice lesson from your post:

NEVER TRUST MICRO$OFT !!!

;-)

Thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top