Need help in understanding for loop in c++

  • Thread starter silverburgh.meryl
  • Start date
S

silverburgh.meryl

Hi,

I need some help in understanding the following for() loop:

for (PRBool isRoot;
mCSSUtils->IsRuleNodeRoot(ruleNode, &isRoot), !isRoot;
mCSSUtils->GetRuleNodeParent(ruleNode, &ruleNode))

what is the middle clause for?
Why there is a ',' in the middle? And what does that mean?
 
J

Jerry Coffin

Hi,

I need some help in understanding the following for() loop:

for (PRBool isRoot;
mCSSUtils->IsRuleNodeRoot(ruleNode, &isRoot), !isRoot;
mCSSUtils->GetRuleNodeParent(ruleNode, &ruleNode))

what is the middle clause for?
Why there is a ',' in the middle? And what does that mean?

It looks like this is attempting to traverse from a current node to a
root node in a threaded tree, or something on that general order.

The middle clause is a test, just like usual. The comma operator
evaluates its left operand, discards the result, then evaluates the
right operand. The result of the right operand becomes the result of the
whole expression.

In this case, it's calling "IsRuleNodeRoot", which apparently looks at a
node, figures out whether it's a root node, and sets some sort of semi-
boolean (a pointer to which is passed as a the second parameter) to tell
you that result. In this case, that variable (isRoot) is evaluated as
the right operand of the comma operator, so what it's doing it calling
the function to set the variable, then evaluating the variable itself to
determine whether it's reached the root yet, and continuing the loop
until it reaches the root.
 

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
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top