Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
WhileDo.cs
1using System.Threading.Tasks;
6
8{
12 public class WhileDo : BinaryOperator
13 {
22 public WhileDo(ScriptNode Condition, ScriptNode Statement, int Start, int Length, Expression Expression)
23 : base(Condition, Statement, Start, Length, Expression)
24 {
25 }
26
33 {
35 BooleanValue Condition;
36
37 Condition = this.left.Evaluate(Variables) as BooleanValue;
38 if (Condition is null)
40
41 while (Condition.Value)
42 {
43 try
44 {
45 Last = this.right.Evaluate(Variables);
46 }
48 {
49 if (ex.HasLoopValue)
50 Last = ex.LoopValue;
51
52 //ScriptBreakLoopException.Reuse(ex);
53 break;
54 }
56 {
57 if (ex.HasLoopValue)
58 Last = ex.LoopValue;
59
60 //ScriptContinueLoopException.Reuse(ex);
61 }
62
63 Condition = this.left.Evaluate(Variables) as BooleanValue;
64 if (Condition is null)
66 }
67
68 return Last;
69 }
70
76 public override async Task<IElement> EvaluateAsync(Variables Variables)
77 {
78 if (!this.isAsync)
79 return this.Evaluate(Variables);
80
82 BooleanValue Condition;
83
84 Condition = await this.left.EvaluateAsync(Variables) as BooleanValue;
85 if (Condition is null)
87
88 while (Condition.Value)
89 {
90 try
91 {
92 Last = await this.right.EvaluateAsync(Variables);
93 }
95 {
96 if (ex.HasLoopValue)
97 Last = ex.LoopValue;
98
99 //ScriptBreakLoopException.Reuse(ex);
100 break;
101 }
103 {
104 if (ex.HasLoopValue)
105 Last = ex.LoopValue;
106
107 //ScriptContinueLoopException.Reuse(ex);
108 }
109
110 Condition = await this.left.EvaluateAsync(Variables) as BooleanValue;
111 if (Condition is null)
113 }
114
115 return Last;
116 }
117 }
118}
Exception thrown if condition does not evaluate to a Boolean value.
IElement LoopValue
Value to include in the loop's result.
bool HasLoopValue
If LoopValue contains a value that should be included in the loop's result.
Class managing a script expression.
Definition: Expression.cs:41
Base class for all binary operators.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:88
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: WhileDo.cs:32
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: WhileDo.cs:76
WhileDo(ScriptNode Condition, ScriptNode Statement, int Start, int Length, Expression Expression)
WHILE-DO operator.
Definition: WhileDo.cs:22
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21