10 examples of 'go for loop array' in Go

Every line of 'go for loop array' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
1246func (p *Planner) planArrayComprehension(ac *ast.ArrayComprehension, iter planiter) error {
1247
1248 larr := p.newLocal()
1249
1250 p.appendStmt(&ir.MakeArrayStmt{
1251 Target: larr,
1252 })
1253
1254 return p.planComprehension(ac.Body, func() error {
1255 return p.planTerm(ac.Term, func() error {
1256 p.appendStmt(&ir.ArrayAppendStmt{
1257 Value: p.ltarget,
1258 Array: larr,
1259 })
1260 return nil
1261 })
1262 }, larr, iter)
1263}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

128func LoopIndirect(vValue reflect.Value) reflect.Value {
129 for vValue.Kind() == reflect.Ptr {
130 vValue = vValue.Elem()
131 }
132 return vValue
133}
381func (self *_parser) parseFor(idx file.Idx, initializer ast.Expression) *ast.ForStatement {
382
383 // Already have consumed "<initializer> ;"
384
385 var test, update ast.Expression
386
387 if self.token != token.SEMICOLON {
388 test = self.parseExpression()
389 }
390 self.expect(token.SEMICOLON)
391
392 if self.token != token.RIGHT_PARENTHESIS {
393 update = self.parseExpression()
394 }
395 self.expect(token.RIGHT_PARENTHESIS)
396
397 return &ast.ForStatement{
398 For: idx,
399 Initializer: initializer,
400 Test: test,
401 Update: update,
402 Body: self.parseIterationStatement(),
403 }
404}
522func (v *Dumper) StmtForeach(n *ast.StmtForeach) {
523 v.print(0, "&ast.StmtForeach{\n")
524 v.indent++
525
526 v.dumpPosition(n.Position)
527 v.dumpToken("ForeachTkn", n.ForeachTkn)
528 v.dumpToken("OpenParenthesisTkn", n.OpenParenthesisTkn)
529 v.dumpVertex("Expr", n.Expr)
530 v.dumpToken("AsTkn", n.AsTkn)
531 v.dumpVertex("Key", n.Key)
532 v.dumpToken("DoubleArrowTkn", n.DoubleArrowTkn)
533 v.dumpToken("AmpersandTkn", n.AmpersandTkn)
534 v.dumpVertex("Var", n.Var)
535 v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn)
536 v.dumpToken("ColonTkn", n.ColonTkn)
537 v.dumpVertex("Stmt", n.Stmt)
538 v.dumpToken("EndForeachTkn", n.EndForeachTkn)
539 v.dumpToken("SemiColonTkn", n.SemiColonTkn)
540
541 v.indent--
542 v.print(v.indent, "},\n")
543}
532func (v *SequenceDiagramVisitor) visitLoopN(e *StatementElement, i int, c *sysl.LoopN) error {
533 return v.visitGroupStmt(e, c.GetStmt(), e.isLastStmt(i), "loop %d times\n", c.GetCount())
534}
444func (p *parser) For() Node {
445 pos := p.curt.Pos
446 lstart := p.nextLabel()
447 lend := p.nextLabel()
448 var init, cond, step Expr
449 p.expect(cpp.FOR)
450 p.expect('(')
451 if p.curt.Kind != ';' {
452 init = p.Expr()
453 }
454 p.expect(';')
455 if p.curt.Kind != ';' {
456 cond = p.Expr()
457 }
458 p.expect(';')
459 if p.curt.Kind != ')' {
460 step = p.Expr()
461 }
462 p.expect(')')
463 p.pushBreakCont(lend, lstart)
464 body := p.Stmt()
465 p.popBreakCont()
466 return &For{
467 Pos: pos,
468 Init: init,
469 Cond: cond,
470 Step: step,
471 Body: body,
472 LStart: lstart,
473 LEnd: lend,
474 }
475}
920func parseLoop(obj Object, ctx *ParseContext) *LoopExpr {
921 return (*LoopExpr)(parseLetLoop(obj, true, ctx))
922}
1652func (vis *bodySafetyVisitor) checkArrayComprehensionSafety(ac *ArrayComprehension) {
1653 ac.Body = vis.checkComprehensionSafety(ac.Term.Vars(), ac.Body)
1654}
1898func (p *Parser) forClause(s *Stmt) {
1899 fc := &ForClause{ForPos: p.pos}
1900 p.next()
1901 fc.Loop = p.loop(fc.ForPos)
1902
1903 start, end := "do", "done"
1904 if pos, ok := p.gotRsrv("{"); ok {
1905 if p.lang == LangPOSIX {
1906 p.langErr(pos, "for loops with braces", LangBash, LangMirBSDKorn)
1907 }
1908 fc.DoPos = pos
1909 fc.Braces = true
1910 start, end = "{", "}"
1911 } else {
1912 fc.DoPos = p.followRsrv(fc.ForPos, "for foo [in words]", start)
1913 }
1914
1915 s.Comments = append(s.Comments, p.accComs...)
1916 p.accComs = nil
1917 fc.Do, fc.DoLast = p.followStmts(start, fc.DoPos, end)
1918 fc.DonePos = p.stmtEnd(fc, "for", end)
1919 s.Cmd = fc
1920}
1734func (b *builder) forStmt(fn *Function, s *ast.ForStmt, label *lblock) {
1735 // ...init...
1736 // jump loop
1737 // loop:
1738 // if cond goto body else done
1739 // body:
1740 // ...body...
1741 // jump post
1742 // post: (target of continue)
1743 // ...post...
1744 // jump loop
1745 // done: (target of break)
1746 if s.Init != nil {
1747 b.stmt(fn, s.Init)
1748 }
1749 body := fn.newBasicBlock("for.body")
1750 done := fn.newBasicBlock("for.done") // target of 'break'
1751 loop := body // target of back-edge
1752 if s.Cond != nil {
1753 loop = fn.newBasicBlock("for.loop")
1754 }
1755 cont := loop // target of 'continue'
1756 if s.Post != nil {
1757 cont = fn.newBasicBlock("for.post")
1758 }
1759 if label != nil {
1760 label._break = done
1761 label._continue = cont
1762 }
1763 emitJump(fn, loop, s)
1764 fn.currentBlock = loop
1765 if loop != body {
1766 b.cond(fn, s.Cond, body, done)
1767 fn.currentBlock = body
1768 }
1769 fn.targets = &targets{
1770 tail: fn.targets,
1771 _break: done,
1772 _continue: cont,
1773 }
1774 b.stmt(fn, s.Body)
1775 fn.targets = fn.targets.tail
1776 emitJump(fn, cont, s)
1777
1778 if s.Post != nil {
1779 fn.currentBlock = cont
1780 b.stmt(fn, s.Post)
1781 emitJump(fn, loop, s) // back-edge
1782 }
1783 fn.currentBlock = done
1784}

Related snippets