Book a Demo

Author Topic: Using Loop Nodes  (Read 14762 times)

tonyhedge

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Using Loop Nodes
« on: January 12, 2011, 09:43:24 pm »
OK, I'm lost!

I've been trying to use a Loop Node to represent a simple C++ for loop. Take a trivial example:

for (unsigned int i = 0; i < n; i++)
{
    DoStuff();
}

where DoStuff() is a method in the same class.

What I think I need to do is put an Action in the Setup node to represent "i =0",  an Action in the Body node to represent "i++" and an Action in the Test node to represent "i < n".

I think DoStuff() then needs to be an Activity outside the Loop Node.

 If I'm right so far, then it avoids the problem that Tadguy is havings (see a few posts below).

But how does the Activity diagram look - how do I join everything up?

I've done a lot of searching around all the usual places, from which I'm rapidly reaching the conclusion that no one else really understands Loop Nodes yet either!

Any help, guidance, links welcome - even if they are telling me I'm stupid!

Tony
"Interrupts happen!"

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Using Loop Nodes
« Reply #1 on: January 13, 2011, 11:19:14 am »
Hi Tony,

I haven't used Loop Nodes "in Anger", but my thought would be that the i++ action is the LAST action in the body rather than the only action.

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

tonyhedge

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Using Loop Nodes
« Reply #2 on: January 13, 2011, 09:15:53 pm »
Thanks Paolo - I'm really not sure. I don't understand whether the LoopNode "body" is trying to model the statement within the loop, or (in C/C++ terminology) the third expression in a for-loop.

Frustratingly I can't find a single example of their actual use in a real Activity diagram anywhere. None of the other tool manufacturers seem to offer more than is in the EA Help.

Thanks again. Any other suggestions comments still most welcome.
"Interrupts happen!"

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Using Loop Nodes
« Reply #3 on: January 13, 2011, 09:22:16 pm »
Tony,

Have a look in the UML superstructure (v 2.3 §12.3.35 p 396)
There is quite an elaborate explanation about loop nodes.
I think it will be helpful.

Geert

tonyhedge

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Using Loop Nodes
« Reply #4 on: January 13, 2011, 09:55:05 pm »
Thanks Geert

I've looked at it before, but have just been back to re-read it.

Quote
... execution of the body section begins. Each front end node in the body section is offered a control token. When all back end nodes in the body section have completed execution, execution of the body section is complete.
Within the body section, variables defined in the loop node or in some higher-level enclosing node are updated with any
new values produced during the iteration and any temporary values are discarded.

My reading of that supports Paolo's argument that to model a C/C++ for-loop the body section consists of (in K&R terminology) the statement followed by expression3 (as the back end node) - ie the assumptions in my first post are wrong (nothing unusual there!).

Interestingly, it's one of the very few sections of the superstructure with no example!

Thanks again - goes to prove that it is always worth re-reading what you have already read.

Tony
"Interrupts happen!"