simple Haskell loop

You could define a recursive function that prints “a string” n times (n being the parameter of the function), like this: A somewhat more general approach would be to define a function that repeats any IO action n times: The above function already exists in Control.Monad under the name replicateM_.

When to use “while” or “for” in Python

Yes, there is a huge difference between while and for. The for statement iterates through a collection or iterable object or generator function. The while statement simply loops until a condition is False. It isn’t preference. It’s a question of what your data structures are. Often, we represent the values we want to process as a range (an actual list), or xrange (which … Read more