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

Loops #45

Closed
kengorab opened this issue Aug 1, 2019 · 0 comments
Closed

Loops #45

kengorab opened this issue Aug 1, 2019 · 0 comments

Comments

@kengorab
Copy link
Owner

kengorab commented Aug 1, 2019

I should be able to loop, either over a range of data or until a certain condition is no longer true.

var a = 0
while a < 3 {
  a = a + 1
}
a  // 2

var greeting = "He"
for ch in ["l", "l", "o"] {
  greeting = greeting + ch
}

// This would also produce the same effect, since strings should be considered iterable:
for ch in "llo" { .. }

// Also, to obtain the index there is an optional second parameter
for ch, idx in ["l", "l", "o"] {
  println("Index: " + idx)
  greeting = greeting + ch
}

// The `range` builtin can also be used to iterate over ranges
var sum = 0
for i in range(0, 10) {
  sum = sum + i
}

Loops can also be infinite-loops, meaning that they will continue to loop until a break keyword is met

var a = 0
while a < 3 {
  a = a - 1  // a will always be less than 3, so infinite loop occurs
  if a == -100 {
    break
  }
}
@kengorab kengorab created this issue from a note in Language Core (To Do) Aug 1, 2019
@kengorab kengorab moved this from To Do to In Progress in Language Core Aug 8, 2019
@kengorab kengorab moved this from In Progress to Done in Language Core Aug 22, 2019
@kengorab kengorab moved this from Done to New Done in Language Core May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant