Ce contenu n’est pas encore disponible dans votre langue.
from flojoy import ( flojoy, Scalar, OrderedPair, SmallMemory, NodeReference, ) from typing import Optional memory_key = "LOOP_INDEX" @flojoy def LOOP_INDEX( loop_node: NodeReference, default: Optional[OrderedPair | Scalar] = None, ) -> Scalar: """Load the loop index from the LOOP node. A loop index in Flojoy starts at 1 and increases by 1 for each loop. Parameters ---------- loop_node : str The LOOP node to track the loop index from. Returns ------- Scalar The loop index in Scalar form. """ ref_loop_node = loop_node.unwrap() if ref_loop_node == "" or "LOOP" not in ref_loop_node: raise ValueError("A LOOP node id must be given.") loop_info = SmallMemory().read_memory(ref_loop_node, "loop-info") if loop_info is None: c = 1 else: c = loop_info.get("current_iteration") return Scalar(c=float(c))
This example shows a simple way to create a loop with Flojoy. First, you’ll need to place these three nodes:
LOOPnode which will define the number of loops.
LOOP_INDEXnode tracks the loop index (the number of loops that has occured). The index starts at 1 in Flojoy.
BIG_NUMBERnode which is connected to the “end” output of the [
LOOP] node, which serve, to terminate the program.
Then click on [
LOOP] and change the number of loops to 100 (the default is -1 which causes the loop to repeat indefinitely). Click on [
LOOP_INDEX] and change the referred node to [
You can then run the app and watch the loop index increase to 100 as the loop continues.