for X in range(1,11):
print ("{:>4}".format(X), end = " ")
print()
for X in range(1,11):
print ("{:>4}".format(X), end = " “)
while Y <= 10:
print (”{:>4}".format(X * Y), end = " ")
Y += 1
print()
Y=1
Here are a other example:
i = 2
while(i < 100):
j = 2
while(j <= (i/j)):
if not(i%j): break
j = j + 1
if (j > i/j) : print i, " is prime"
i = i + 1
print “Good bye!”
It should create a list of numbers… …how is the translation regarding Print and OUT? There are other translations f.e. print and return. I try to find the gramma between python, C#, … designScript
How can i transform this to designscript, here are my trys: for_while_loop_loop.dyn (3.0 KB)
I changed the “prints” to “returns”, but dynamo is still confused, because the returns at wrong points…!
I think i have to change more the Syntax.
I’m not sure exactly what you want to get… But just to try and clarify…
OUT is everything you want to output… so to ‘print’… make a variable equal the value you want to ‘print’, then output that variable… E.G…
if (j > i/j) : print str(i) + ' is prime'
is changed to
if (j > i/j) : k = str(i) + ' is prime'
OUT = k
The loops themselves are quite complex, so it’s hard to see what they are meant to be? I’d test on a more simple example until you’re comfortable with them…
If you use append, you’ll see the progression of numbers which might make the process more obvious?
Perhaps have a play with this… FYI, the <> will let you format code… and if you use ’ not " then it will copy and paste into here easier…
i = IN[0]
z = []
while(i < 50):
j = 2
z.append(j)
if not(i%j): break
i = i + 1
OUT = z