2023-03-09 23:57:16 +00:00
|
|
|
namespace tlang
|
|
|
|
{
|
|
|
|
internal class ForLoop : Node
|
|
|
|
{
|
|
|
|
public Node Init {get;set;}
|
|
|
|
public Node Condition {get;set;}
|
|
|
|
public Node Increment {get;set;}
|
|
|
|
public Node Body {get;set;}
|
|
|
|
|
|
|
|
public ForLoop(Node init, Node condition, Node inc, Node body)
|
|
|
|
{
|
|
|
|
Init = init;
|
|
|
|
Condition = condition;
|
|
|
|
Increment = inc;
|
|
|
|
Body = body;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override TObject Execute(IScopeEnvironment nodeEnv)
|
|
|
|
{
|
|
|
|
var env = nodeEnv.SubEnv;
|
|
|
|
bool isRunning=true;
|
|
|
|
env["last_ittr"]= new TExternalMethod((args)=>{
|
2023-06-08 18:14:35 +00:00
|
|
|
|
2023-03-09 23:57:16 +00:00
|
|
|
isRunning=false;
|
2023-06-08 18:14:35 +00:00
|
|
|
return TObject.True;
|
2023-03-09 23:57:16 +00:00
|
|
|
});
|
|
|
|
Init.Execute(env);
|
2023-06-08 18:14:35 +00:00
|
|
|
TObject obj= TObject.Uninit;
|
2023-03-09 23:57:16 +00:00
|
|
|
while(Condition.Execute(env).AsBoolean && isRunning)
|
|
|
|
{
|
|
|
|
obj=Body.Execute(env);
|
|
|
|
Increment.Execute(env);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|