If you write Python loops, you can already write Mojo loops. The syntax is the same: for, while, break, continue.
To repeat something n times, use for _ in range(n):
Comprehensions work, too, i.e. [x * x for x in range(5)]
The biggest difference is speed. Mojo compiles your loop to native machine code, while Python interprets one step at a time.
We counted the primes below 2 million with the same trial-division loop in both languages (no sieve): Python took 2.8 seconds, Mojo took 57 ms.
More quick references in the Mojo cheat sheets: https://t.co/SIz87amjpm
🔥 Feature Engineering & Data Pipeline Challenge:
Before feeding 50GB of training features into your ML models, how you handle joins and missing data in Python determines whether your preprocessing node survives or hits an OOM crash. Drop your stack on the main post below 👇
https://t.co/ZgD2VjYQAi