38 lines
981 B
C#
38 lines
981 B
C#
namespace tlang
|
|
{
|
|
public class WhileLoop : Node
|
|
{
|
|
public Node Condition {get;set;}
|
|
public Node Body {get;set;}
|
|
public bool DoLoop {get;set;}
|
|
|
|
public WhileLoop(Node condition, Node yes, bool v)
|
|
{
|
|
Condition = condition;
|
|
Body = yes;
|
|
DoLoop = v;
|
|
}
|
|
|
|
public override TObject Execute(IScopeEnvironment nodeEnv)
|
|
{
|
|
bool isRunning=true;
|
|
var env = nodeEnv.SubEnv;
|
|
|
|
env["last_ittr"]= new TExternalMethod((args)=>{
|
|
isRunning=false;
|
|
return new TNumber(1);
|
|
});
|
|
|
|
TObject obj=new TUninit();
|
|
|
|
if(!DoLoop) isRunning = Condition.Execute(env).AsBoolean;
|
|
while(isRunning)
|
|
{
|
|
|
|
obj=Body.Execute(env);
|
|
isRunning = Condition.Execute(env).AsBoolean;
|
|
}
|
|
return obj;
|
|
}
|
|
}
|
|
} |