12.6.3 The for Statement
338011
private ParseTree parseForStatement(SourcePosition start, ParseTree initializer) {
    if (initializer == null) {
      initializer = new NullTree(getTreeLocation(getTreeStartLocation()));
    }
    eat(TokenType.SEMI_COLON);

    ParseTree condition;
    if (!peek(TokenType.SEMI_COLON)) {
      condition = parseExpression();
    } else {
      condition = new NullTree(getTreeLocation(getTreeStartLocation()));
    }
    eat(TokenType.SEMI_COLON);

    ParseTree increment;
    if (!peek(TokenType.CLOSE_PAREN)) {
      increment = parseExpression();
    } else {
      increment = new NullTree(getTreeLocation(getTreeStartLocation()));
    }
    eat(TokenType.CLOSE_PAREN);
    ParseTree body = parseStatement();
    return new ForStatementTree(getTreeLocation(start), initializer, condition, increment, body);
  }
1003000
def statement(self, i):
        
    # ----- This code is just to avoid creating a new list and
    #       returning a custom exception message.
        o = len(self.body)
        n = o + len(self.else_body)
        if i >= 0 and i < n:
            if i < o:
                return self.body.statement(i)
            return self.else_body.statement(i - o)
        elif i < 0 and i >= -n:
            if i >= o - n:
                return self.else_body.statement(i)
            return self.body.statement(i - o + n)
        raise IndexError('statement index out of range')
680338
function forIn(object, fn, scope) {
    var symbols,
        k,
        i,
        l;

    for (k in object)
      fn.call(scope || null, k, object[k]);

    if (Object.getOwnPropertySymbols) {
      symbols = Object.getOwnPropertySymbols(object);

      for (i = 0, l = symbols.length; i < l; i++)
        fn.call(scope || null, symbols[i], object[symbols[i]]);
    }
  }
1302265
public static Statement forLoop(String localVar, Expression limit, Statement body) {
    return For.create(localVar, Expression.number(0), limit, Expression.number(1), body);
  }
693426
def p_generate_for(self, p):
        ''
        p[0] = ForStatement(p[3], p[4], p[5], p[7], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
119227
def p_for_sentence_start(p):
    
    gl.LOOPS.append(('FOR', p[2]))
    p[0] = None

    if p[4] is None or p[6] is None or p[7] is None:
        return

    if is_number(p[4], p[6], p[7]):
        if p[4].value != p[6].value and p[7].value == 0:
            warning(p.lineno(5), 'STEP value is 0 and FOR might loop forever')

        if p[4].value > p[6].value and p[7].value > 0:
            warning(p.lineno(5), 'FOR start value is greater than end. This FOR loop is useless')

        if p[4].value < p[6].value and p[7].value < 0:
            warning(p.lineno(2), 'FOR start value is lower than end. This FOR loop is useless')

    id_type = common_type(common_type(p[4], p[6]), p[7])
    variable = SYMBOL_TABLE.access_var(p[2], p.lineno(2), default_type=id_type)
    if variable is None:
        return

    variable.accessed = True
    expr1 = make_typecast(variable.type_, p[4], p.lineno(3))
    expr2 = make_typecast(variable.type_, p[6], p.lineno(5))
    expr3 = make_typecast(variable.type_, p[7], p.lexer.lineno)

    p[0] = make_sentence('FOR', variable, expr1, expr2, expr3)
980550
function forAll(arr, fn) {
    var out = [], i;
    for (i = 0; i < arr.length; i++) {
        out.push(fn(arr[i], i));
    }

    return out;
}
1166492
def p_iteration_statement_1(self, p):
        
        p[0] = ast.DoWhile(predicate=p[5], statement=p[2])
230552
def for(queue:, worker: nil)
      worker_name = worker.to_s.underscore.tr("/", "_") if worker
      [namespace, queue, worker_name].compact.join(".")
    end
1123835
function(_part){
        if (_part[2]!='as')
            throw 'bad for list loop statement: '+_part.join(' ');
        var _seq = _part[1].split('..');
        if (_seq.length>1){
            // {list 1..100 as x}
            _doParseVars(_seq[0]);
            _doParseVars(_seq[1]);
            return 'for(var '+_part[3]+','+_part[3]+'_index=0,'+
                        _part[3]+'_beg='+_seq[0]+','+_part[3]+'_end='+_seq[1]+','+
                        _part[3]+'_length=parseInt('+_part[3]+'_end-'+_part[3]+'_beg+1);'+
                        _part[3]+'_index<'+_part[3]+'_length;'+_part[3]+'_index++){'+
                        _part[3]+' = '+_part[3]+'_beg+'+_part[3]+'_index;';
        }else{
            // {list seq as x}
            // seq is array [1,2,4]
            _doParseVars(_part[1]);
            return 'for(var __LIST__'+_part[3]+' = '+_part[1]+','+
                        _part[3]+','+_part[3]+'_index=0,'+
                        _part[3]+'_length=__LIST__'+_part[3]+'.length;'+
                        _part[3]+'_index<'+_part[3]+'_length;'+_part[3]+'_index++){'+
                        _part[3]+' = __LIST__'+_part[3]+'['+_part[3]+'_index];';
        }
    }
594683
def p_iteration_statement_6(self, p):
        
        p[0] = ast.ForIn(item=ast.VarDecl(identifier=p[4], initializer=p[5]),
                         iterable=p[7], statement=p[9])
693607
def p_iteration_statement_5(self, p):
        
        vardecl = self.asttypes.VarDeclNoIn(identifier=p[4])
        vardecl.setpos(p, 3)
        p[0] = self.asttypes.ForIn(item=vardecl, iterable=p[6], statement=p[8])
        p[0].setpos(p)
854473
def p_try_statement_2(self, p):
        """"""
        p[0] = ast.Try(statements=p[2], fin=p[3])
200081
private final Statement forStatement(Data data) throws TemplateException {

	int pos = data.srcCode.getPos();

	// id
	String id = variableDec(data, false);
	if (id == null) {
	    data.srcCode.setPos(pos);
	    return null;
	}
	if (id.equalsIgnoreCase("for")) {
	    id = null;
	    data.srcCode.removeSpace();
	    if (!data.srcCode.forwardIfCurrent('(')) {
		data.srcCode.setPos(pos);
		return null;
	    }
	}
	else {
	    data.srcCode.removeSpace();
	    if (!data.srcCode.forwardIfCurrent(':')) {
		data.srcCode.setPos(pos);
		return null;
	    }
	    data.srcCode.removeSpace();

	    if (!data.srcCode.forwardIfCurrent("for", '(')) {
		data.srcCode.setPos(pos);
		return null;
	    }
	}

	Expression left = null;
	Body body = new BodyBase(data.factory);
	Position line = data.srcCode.getPosition();
	comments(data);
	if (!data.srcCode.isCurrent(';')) {
	    // left
	    left = expression(data);
	    comments(data);
	}
	// middle for
	if (data.srcCode.forwardIfCurrent(';')) {

	    Expression cont = null;
	    Expression update = null;
	    // condition
	    comments(data);
	    if (!data.srcCode.isCurrent(';')) {
		cont = condition(data);
		comments(data);
	    }
	    // middle
	    if (!data.srcCode.forwardIfCurrent(';')) throw new TemplateException(data.srcCode, "invalid syntax in for statement");
	    // update
	    comments(data);
	    if (!data.srcCode.isCurrent(')')) {
		update = expression(data);
		comments(data);
	    }
	    // start )
	    if (!data.srcCode.forwardIfCurrent(')')) throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
	    // ex block
	    Body prior = data.setParent(body);
	    statement(data, body, CTX_FOR);

	    // performance improvment in special constellation
	    // TagLoop loop = asLoop(data.factory,left,cont,update,body,line,data.srcCode.getPosition(),id);
	    // if(loop!=null) return loop;

	    data.setParent(prior);

	    return new For(data.factory, left, cont, update, body, line, data.srcCode.getPosition(), id);
	}
	// middle foreach
	else if (data.srcCode.forwardIfCurrent("in")) {
	    // condition
	    comments(data);
	    Expression value = expression(data);
	    comments(data);
	    if (!data.srcCode.forwardIfCurrent(')')) throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");

	    // ex block
	    Body prior = data.setParent(body);
	    statement(data, body, CTX_FOR);
	    data.setParent(prior);

	    if (!(left instanceof Variable)) throw new TemplateException(data.srcCode, "invalid syntax in for statement, left value is invalid");

	    // if(!(value instanceof Variable))
	    // throw new TemplateException(data.srcCode,"invalid syntax in for statement, right value is
	    // invalid");
	    return new ForEach((Variable) left, value, body, line, data.srcCode.getPosition(), id);
	}
	else throw new TemplateException(data.srcCode, "invalid syntax in for statement");
    }
1169260
def statement(self):
        
        return (self.assignment ^ self.expression) + Suppress(
            self.syntax.terminator)
1190192
def statement_after(self, i):
        """"""
        k = i + 1
        o = len(self.body)
        n = o + len(self.else_body)
        if k > 0:
            if k < o:
                return self.body.statement(k)
            if k > o and k < n:
                return self.else_body.statement(k)
        if k < 0:
            if k < o - n and k > -n:
                return self.body.statement(k)
            if k > o - n:
                return self.else_body.statement(k)
        return None
1177536
function ForItemData(forElement, item, index) {
    this.parent = forElement.scope;
    this.raw = {};
    this.listeners = [];

    this.directive = forElement.aNode.directives['for']; // eslint-disable-line dot-notation
    this.indexName = this.directive.index || '$index';

    this.raw[this.directive.item] = item;
    this.raw[this.indexName] = index;
}