New for loop syntax #2033
Replies: 2 comments 1 reply
-
Consider how Python addresses this use-case: for i in range(0, 10, 2):
print(i) Here, By moving functionality into libraries, we're able to keep the language simple and make it easier to evolve in the long term. By reusing a singular |
Beta Was this translation helpful? Give feedback.
-
@Tomttth I see you double posted this with #482. Please refrain from double posting comments, it's not helpful. |
Beta Was this translation helpful? Give feedback.
-
Hello I would like to point out like instead of using the original for(;;) syntax, why can't we use a new syntax like:
for i = 0 wr i<n stp 2:
Console.print(I)
stp 2 would be converted to i = i +2
stp -2 would be converted to I = i-2
If we don't initialize i like:
for i wr i <n stp 2:
Console.Print(I)
Then by default i will have 0 as initial value
For getting a range function like syntax as in python we use:
for i frm 2 to 10:
Console. Print(i)
//which will print 2 to (n-1) 10
For each loop syntax for iterables Or arrays:
for i in arrays:
Console.Print(i)
This will cause for loop to infer type from array or list for i and then it will loop through array.
I think this is more intuitive
Beta Was this translation helpful? Give feedback.
All reactions