locked
"break" and "continue" statements in WF loops RRS feed

  • Question

  • Hi,
    Are there any analogues to these statements in Loop activities in WF 4.0?
    How can I implement such within While, For etc...?

    10x,
    Guy 
    Tuesday, December 1, 2009 10:14 AM

Answers

  • We don't have Break and Continue activities in the box. As said in the previous post, this can be implemented easily using a Flowchart.

    Break behavior can be also achieved with procedural activities using a combination of Variables and basic Control Flow activities. The sample located at %SamplesRoot%\WF\Basic\Built-InActivities\EmulatingBreakInWhile shows how to emulate a Break inside of a While

    Leon Welicki,
    Program Manager, WF
    Tuesday, December 1, 2009 6:12 PM

All replies

  • Hi,

    I'm not aware of any specific activities to be used inside e.g. a While activity. Yet the easiest way to model this behavior I could think of would be taking a FlowChart activity and creating the loop manually e.g. starting with a FlowDecision. This way you could explicitly branch back to the starting point of the loop or prematurely get out of it altogether.

    Depending on your actual needs explicit child activity scheduling using the runtime on a custom activity could also be an option.

    Best regards,
    mario
    • Proposed as answer by Xiaowen Xin Tuesday, December 1, 2009 12:38 PM
    Tuesday, December 1, 2009 10:57 AM
  • We don't have Break and Continue activities in the box. As said in the previous post, this can be implemented easily using a Flowchart.

    Break behavior can be also achieved with procedural activities using a combination of Variables and basic Control Flow activities. The sample located at %SamplesRoot%\WF\Basic\Built-InActivities\EmulatingBreakInWhile shows how to emulate a Break inside of a While

    Leon Welicki,
    Program Manager, WF
    Tuesday, December 1, 2009 6:12 PM
  • Thanks Leon, but the sample you mentioned is kind of lame "break" since if you have more activities in the sequence after the activity who ask for break these activities will be executed, so it is no immediate break only change in the loop condition for the next iteration.

    10x,
    Guy
    Wednesday, December 2, 2009 5:51 AM
  • Unfortunately, since we don't have these activities in the box break-like scenarios need to be implemented manually using a combination of variables, expressions, and If activities.  The idea in that sample is controlling the condition in the If activity, which would provoke the While to break (actually, the condition completes). As you noted in your comment, this is not a "direct" way of breaking since you need to do the work yourself. This setting is to be used in simple process definitions (for more complex ones it may get hard to read). As it was suggested earlier in this thread, you can also use Flowchart activity...Have you tried this? If so, did it helped to model your process?

    Thursday, December 3, 2009 3:37 AM
  • Thanks Leon, No, I didn't tried the FlowChart option yes. I'll update when I will....
    Thursday, December 3, 2009 9:39 AM