Icon

6. Loop on Condition

<p><strong>Loop on a Condition</strong></p><p>This workflow implements an example of a loop on a condition using the <em>Variable Condition Loop End</em> node. This means, the loop stops only when a certain condition is met which is defined in the <em>Variable Condition Loop End</em> node.</p><p>Let's imagine the following game:</p><p>We think of a number an write it into the <em>Table Creator</em> node. Then we start the loop with a <em>Generic Loop Start</em> node. In the loop, we prompt the user to guess the number we have thought of. They can write their guess into the <em>String Widget</em> node. If the answer is wrong, the user is prompted again until the answer is right OR he has already tried 3 times. The condition is built by the <em>Variable Expression</em> node and represented by the flow variable "success" (0 if guess is wrong, 1 if guess is right OR when the number of iteration is 3). The <em>Variable Condition Loop End</em> node then ends the loop under the condition when "success" equals the value 1.</p><p>This workflow should be executed as a Data App on the KNIME Hub since there the <em>Widget </em>node makes the workflow stop to collect the user guess at each iteration.</p>

Workflow: Loop on a Condition


This workflow implements an example of a loop on a condition using the Variable Condition Loop End node. This means, the loop stops only when a certain condition is met which is defined in the Variable Condition Loop End node.

Let's imagine the following game:

We think of a number an write it into the Table Creator node. Then we start the loop with a Generic Loop Start node. In the loop, we prompt the user to guess the number we have thought of. They can write their guess into the String Widget node. If the answer is wrong, the user is prompted again until the answer is right OR he has already tried 3 times. The condition is built by the Variable Expression node and represented by the flow variable "success" (0 if guess is wrong, 1 if guess is right OR when the number of iteration is 3). The Variable Condition Loop End node then ends the loop under the condition when "success" equals the value 1.

This workflow should be executed as a Data App on the KNIME Hub since there the Widget node makes the workflow stop to collect the user guess at each iteration.

Enter the solution

Loop body

Execute the until correct guess but max 3 times.

Correct answer
Table Row to Variable
Solution
Table Creator
Define end condition: Correct guess or more than 3 attempts
Variable Condition Loop End
Define success condition
Variable Expression
Append "guess" to data
Variable to Table Column
Generic Loop Start
Guess number
Integer Widget

Nodes

Extensions

Links