For Loop


Node Information
Loops from a given number to a specified number.
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Loop IN RUN MULTIPLE FALSE FALSE
From IN Int32 ONE FALSE FALSE
To IN Int32 ONE FALSE FALSE
Break IN RUN MULTIPLE FALSE FALSE
Body OUT RUN MULTIPLE FALSE FALSE
Current OUT Int32 MULTIPLE FALSE FALSE
Complete OUT RUN MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Loops
{
    [IsNode("For Loop")]
    public class ForLoop : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Loop");
        Port start = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "From");
        Port end = new Port(PortType.IN, typeof(int), AcceptsLinks.ONE, "To");
        Port loopbreak = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Break");
        Port current = new Port(PortType.OUT, typeof(int), AcceptsLinks.MULTIPLE, "Current");
        Port runout = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Body");
        Port complete = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Complete");
        public int From
        {
            set { start.Value = value.ToString(); }
            get { return GetRuntimeValue(start); }
        }
        public int To
        {
            set { end.Value = value.ToString(); }
            get { return GetRuntimeValue(end); }
        }
        public bool Reverse
        {
            set { Settings[0] = value.ToString(); }
            get { return bool.Parse(Settings[0]); }
        }
        public ForLoop()
        {
            this.NodeType = KGraph.NodeType.Method;
            this.Name = "For Loop";
            From = 0;
            To = 0;
            Reverse = false;
            AddPort(run);
            AddPort(start);
            AddPort(end);
            AddPort(loopbreak);
            AddPort(runout);
            AddPort(current);
            AddPort(complete);
            loopbreak.IsVariable = true;
            loopbreak.VariableType = typeof(bool);
            current.IsVariable = true;
            current.VariableType = typeof(int);
            current.Instructions = "init";
            Information = "Loops from a given number to a specified number.";
        }
        public override string Code()
        {
            string code = string.Empty;
            string revrs = "i++";
            loopbreak.Instructions = loopbreak.ID + "=true;";
            current.Instructions = current.ID;
            if (Reverse) { revrs = "i--"; }
            code = "for (int i = " + GetValue(start) + "; i < "="" +="" getvalue(end)="" +="" ";="" "="" +="" revrs="" +="" ")\r\n"="" +="" "{"="" +="" environment.newline="" +="" current.id="" +="" "="i;\r\n"" +="" getvalue(runout)="" +="" "if="" ("="" +="" loopbreak.id="" +="" "){break;}"="" +="" "}\r\n"="" +="" getvalue(complete);="" return="" code;="" }="" }="" }="">