Loops/N plus one half: Difference between revisions

Content added Content deleted
Line 256: Line 256:
=={{header|Python}}==
=={{header|Python}}==
<python>
<python>
myString = ""
myOutput = []
for i in xrange(1, 11):
for i in xrange(1, 11):
myString += str(i)
myOutput.append(i)
if i == 10:
if i == 10:
break
break
myString += ", "
myOutput.append(", ")
print myString
print ''.join(myOutput)
</python>
</python>

Note: this example uses the Python idiom of building a string as a list and joining the parts together (on an empty string) which is generally far more efficient than instantiating new strings at every step along the way. (Strings are immutable so each expression using "some string" + "some other string" is building new objects rather than appending to existing ones).


=={{header|Scheme}}==
=={{header|Scheme}}==