System.Management.Pash.Implementation.ExecutionVisitor.VisitForStatement C# (CSharp) Method

VisitForStatement() public method

public VisitForStatement ( System.Management.Automation.Language.ForStatementAst forStatementAst ) : AstVisitAction
forStatementAst System.Management.Automation.Language.ForStatementAst
return AstVisitAction
        public override AstVisitAction VisitForStatement(ForStatementAst forStatementAst)
        {
            /*
             * The controlling expression for-condition must have type bool or
             * be implicitly convertible to that type. The loop body, which
             * consists of statement-block, is executed repeatedly while the
             * controlling expression tests True. The controlling expression
             * is evaluated before each execution of the loop body.
             *
             * Expression for-initializer is evaluated before the first
             * evaluation of the controlling expression. Expression
             * for-initializer is evaluated for its side effects only; any
             * value it produces is discarded and is not written to the
             * pipeline.
             *
             * Expression for-iterator is evaluated after each execution of
             * the loop body. Expression for-iterator is evaluated for its
             * side effects only; any value it produces is discarded and is
             * not written to the pipeline.
             *
             * If expression for-condition is omitted, the controlling
             * expression tests True.
             */

            if (forStatementAst.Initializer != null)
            {
                EvaluateAst(forStatementAst.Initializer);
            }

            while (forStatementAst.Condition != null ?
                      LanguagePrimitives.ConvertTo<bool>(EvaluateAst(forStatementAst.Condition))
                    : true)
            {
                // TODO: pass loop label
                if (!EvaluateLoopBodyAst(forStatementAst.Body, null))
                {
                    break;
                }
                if (forStatementAst.Iterator != null)
                {
                    EvaluateAst(forStatementAst.Iterator);
                }
            }

            return AstVisitAction.SkipChildren;
        }
ExecutionVisitor