10 examples of 'while loop in python' in Python

Every line of 'while loop in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
202def _while(cond, body, loop_vars, **kwargs):
203 """
204 Ensure that the condition and body of a tensorflow
205 while_loop are invoked
206 """
207
208 print("tf.while_loop")
209 cond(*loop_vars)
210 return body(*loop_vars)
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

315def visit_while(self, node):
316 """increments the branches counter"""
317 branches = 1
318 if node.orelse:
319 branches += 1
320 self._inc_branch(node, branches)
244def visit_While(self, node):
245 test = self.visit(node.test)
246 body = self.visit(node.body)
247 return IR.WhileStmt(test, body)
66def _while_loop(cond, body, loop_vars, # pylint: disable=redefined-outer-name
67 shape_invariants=None, parallel_iterations=10, # pylint: disable=unused-argument
68 back_prop=True, swap_memory=False, # pylint: disable=unused-argument
69 maximum_iterations=None, name=None): # pylint: disable=unused-argument
70 i = 0
71 while (cond(*loop_vars) and
72 (maximum_iterations is None or i < maximum_iterations)):
73 loop_vars = body(*loop_vars)
74 i += 1
75 return loop_vars
500@dispatch(renpy.ast.While)
501def print_while(self, ast):
502 self.indent()
503 self.write("while %s:" % ast.condition)
504
505 self.print_nodes(ast.block, 1)
365def FOR(self, node):
366 """
367 Process bindings for loop variables.
368 """
369 vars = []
370 def collectLoopVars(n):
371 if hasattr(n, 'name'):
372 vars.append(n.name)
373 else:
374 for c in n.getChildNodes():
375 collectLoopVars(c)
376
377 collectLoopVars(node.assign)
378 for varn in vars:
379 if (isinstance(self.scope.get(varn), Importation)
380 # unused ones will get an unused import warning
381 and self.scope[varn].used):
382 self.report(messages.ImportShadowedByLoopVar,
383 node.lineno, varn, self.scope[varn].source.lineno)
384
385 self.handleChildren(node)
749@cxx_loop
750def visit_While(self, node):
751 """
752 Create While node for Cxx generation.
753
754 It is a cxx_loop to handle else clause.
755 """
756 test = self.visit(node.test)
757 body = [self.visit(n) for n in node.body]
758 stmt = While(test, Block(body))
759 return self.process_omp_attachements(node, stmt)
984def p_iteration_statement_2(self, p):
985 """iteration_statement : WHILE LPAREN expr RPAREN statement"""
986 p[0] = ast.While(predicate=p[3], statement=p[5])
428def visit_While(self, ast_node):
429 return self.visit_conditional_stmt(ast_node)
69def test_for():
70 src = dedent("""\
71 for a in [1,2]:
72 a
73
74 for a1 in 1,"":
75 a1
76 """)
77 check_p(src, 1)

Related snippets