Mobile app version of vmapp.org
Login or Join
Sims5801359

: Python single line for loops i'm using processing.py i was following this tut (Java) https://www.youtube.com/watch?v=H7frvcAHXps and i'm wondering if i can use the same kind of for loop in python

@Sims5801359

Posted in: #Python

i'm using processing.py

i was following this tut (Java)


and i'm wondering if i can use the same kind of for loop in python

for(int y = 0; y < height; y = y + cellSize):

for(int x = 0; x < width; x = x + cellSize):

rect(x, 0, cellSize, cellSize)


I receive an error when i try to run the code:

processing.app.SketchException: Maybe there's an unclosed paren or quote mark somewhere before this line?


I guess there's probably an easy but slightly different way to do the use the same kind of nested for loops (on a single line) in python

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sims5801359

1 Comments

Sorted by latest first Latest Oldest Best

 

@Cugini998

def drange(start, stop, step):
"""floating range
code by gimel see:
stackoverflow.com/questions/477486/ """
r = start
while r < stop:
yield r
r += step

for y in drange(0, height, cellSize):
for x in drange(0, width, cellSize):
rect(x, 0, cellSize, cellSize)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme