Navigation:  How-To > Define Element's Behavior >

Example 4: Using Loop

Previous pageReturn to chapter overviewNext page

Example 4: Using Loop

Run This Example in New Window

ForeUI support two kinds of loop:

Loop Multiple Times: will execute the nested content for certain times.
Loop While Condition is Satisfied: will keep looping as long as the condition is satisfied.

ex04_loops

Let's make an example that us loop. Here are the steps:

1. Drag a Button and a TextBox to the plot.

2. Open behavior editor for the button and add the "Element Clicked" event.

3. Click the "Add Flow Control" button and choose "Loop While Condition is Satisfied...".

4. Input the condition, let's set it to "x position of button larger than 100", like this:

ex04_loop

5. Add button element's "Change Location" action into the loop, move the button to left, 10 pixels each time.

6. Add text box's "Change Text" action into the loop, set the text to the x position of the button element.

The final event handler should looks like this:

ex04_event_handler

We can run it now. When we click the button, it keeps moving left a little until its x position equal or less than 100. You can view this online example to see the result.