Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion: clea(n|r)er for loop syntax instead of classic C style one #5944

Closed
jalelegenda opened this issue Jul 23, 2020 · 8 comments
Closed
Labels
Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one.

Comments

@jalelegenda
Copy link

I feel a for loop with the following syntax:

    for i in [1..30] 2 {
        println(i)
    }
  • looks cleaner

  • is more readable

  • involves less typing

than the archaic C-style for loop.

few more examples:

    // counter decrement
    for i in [44..22] -2 {
        println(i)
    }

    // step omitted
    for i in [1..100] {
        println(i)
    }

    // side-by-side
    for i in [1..30] 2 {
        println(i)
    }

    for i := 1; i < 30; i += 2 {
        println(i)
    }
    // it took me 24 minutes just to type the above loop
@jalelegenda jalelegenda added the Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one. label Jul 23, 2020
@Delta456
Copy link
Member

for i in [1..30] 2 {
        println(i)
    }

This doesn't make sense at all.

@ntrel
Copy link
Contributor

ntrel commented Jul 23, 2020

for i := 1; i < 30; i += 2 {

// it took me 24 minutes just to type the above loop

But in that time you learned a useful V programming construct ;-)

@Gladear
Copy link
Member

Gladear commented Jul 23, 2020

for i in 0..30 already works, and extended range are already discussed in #4933 (but, to be honest, it's most unlikely that they will be implemented in the language)

@Delta456
Copy link
Member

If you want these types of ranges then just my range library https://github.com/Delta456/range

@ntrel
Copy link
Contributor

ntrel commented Jul 23, 2020

BTW I've made #5949 to document range for.

@jalelegenda
Copy link
Author

for i in [1..30] 2 {
        println(i)
    }

This doesn't make sense at all.

In what way does it not make sense, please elaborate?

@Delta456
Copy link
Member

Delta456 commented Jul 24, 2020

@jalelegenda [1..30] in V is array slicing and 2 which is step but it seems to be unreadable.

@ryan-willis
Copy link
Member

@jalelegenda
In what way is a C-style for loop unclear? It's clearer to me than your suggestion.

If you're concerned about typing less, you should make use of a text editor that supports creating snippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants