Every line of 'iteration variable' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.
267 func iteration(rv *resolver, in *ast.Iteration) semantic.Statement { 268 v := &semantic.Local{Named: semantic.Named(in.Variable.Value)} 269 rv.mappings.Add(in.Variable, v) 270 iterable := expression(rv, in.Iterable) 271 b, ok := iterable.(*semantic.BinaryOp) 272 if !ok { 273 rv.errorf(in, "iterable can only be range operator, got %T", b) 274 return semantic.Invalid{} 275 } else if b.Operator != ast.OpRange { 276 rv.errorf(in, "iterable can only be range operator, got %s\n", b.Operator) 277 } 278 rv.mappings.Remove(b) // The binary op is no longer referenced directly. 279 out := &semantic.Iteration{AST: in, Iterator: v, From: b.LHS, To: b.RHS} 280 v.Type = iterable.ExpressionType() 281 rv.with(semantic.VoidType, func() { 282 rv.addNamed(v) 283 out.Block = block(rv, in.Block, out) 284 }) 285 rv.mappings.Add(in, out) 286 return out 287 }
888 func (lq *LinqObj) ForEach(line string, scope *Scope, args ...Object) Object { 889 if len(args) != 1 { 890 return NewError(line, ARGUMENTERROR, "1", len(args)) 891 } 892 893 block, ok := args[0].(*Function) 894 if !ok { 895 return NewError(line, PARAMTYPEERROR, "first", "forEach", "*Function", args[0].Type()) 896 } 897 898 s := NewScope(scope, nil) 899 900 next := lq.Query.Iterate() 901 902 for item, ok := next(); ok.Bool; item, ok = next() { 903 s.Set(block.Literal.Parameters[0].(*ast.Identifier).Value, item) 904 Eval(block.Literal.Body, s) 905 } 906 907 return NIL 908 }
107 func (it *Loop) advanceLoop() { 108 // Set the loop iterator to feed from the previous iteration results 109 it.loopEntryIt.SetIterator(it.prevValuesIt) 110 111 // Reset the loop iterator - will also clean the values in the underlying fixed iterator. 112 it.loopIt.Reset() 113 114 it.filterIt.Reset() 115 116 // Increment the completed loops count 117 it.loopsCompleted += 1 118 119 // Mark the loop as finished - no more results can be expected. 120 // Either the number of loops has been executed, or there are 121 // no more expandable nodes. 122 if size, _ := it.prevValuesIt.Size(); (it.bounded && it.loopsCompleted >= it.loops) || size == 0 { 123 it.finished = true 124 } 125 126 // Clean the set of values seen in the previous loop 127 it.prevValuesIt = it.ts.FixedIterator() 128 }