Skip to content
This repository was archived by the owner on Nov 23, 2020. It is now read-only.
This repository was archived by the owner on Nov 23, 2020. It is now read-only.

Design questions about For-Loops #34

@cwkr

Description

@cwkr

I stumbled upon Sparkling because I was searching for a very simple and elegant scripting language. You have designed a very beautiful language, but why is there a For-Loop at all? You have omitted that ugly Switch-Case-Stuff because the same can be done with a chain of Ifs and Elses. As everything that can be done with a For-Loop can also be done with a While-Loop, have you considered replacing the current For-Loop with a Foreach-Loop like construct completely like in Python?

for let i in range(10) {
}
for let i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] {
}

…would do exactly the same as…

for let i = 0; i < 10; i++ {
}

…and is even shorter. If it iterates over Arrays (not HashMaps), you could do stuff like:

for let element in ["str", 5, "str"] {
}
for let key in hm.keys() {
    print(hm[key]);
}

It would also make people happy who don’t like the semicolons in the For-loop (#24) and you could use the newly introduces in keyword as some Kind of contains operator:

if "needle" in haystackarray {
}

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions