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

Add loop statements #8

Open
TheModMaker opened this issue Oct 8, 2022 · 0 comments
Open

Add loop statements #8

TheModMaker opened this issue Oct 8, 2022 · 0 comments
Labels
enhancement New feature or request language A new language feature

Comments

@TheModMaker
Copy link
Owner

Loop statements allow reading a block of fields multiple times. Fields within a loop are converted an array where each element is the loop index. Nested loops create nested arrays. Within the loop, the field can be access directly referring to the current element; outside the loop, the field needs to be indexed. If a conditional is placed in a loop, the elements where the condition isn't taken will be set to null.

For for loops, both the init and step must either be missing or a (possibly compound) assignment.

type Example {
  int32 a;
  for (i = 0; i < a; i+=1) {
    int64 b;
    if (b > 0) {
      int32 c;
    }
  }
  assert b == [1, 0, 2]
  assert c == [9, null, 10]
  assert b[0] == 1;

  set x = 9;
  while (x > 0) {
    int32 d;
    set x -= 1;
  }

  do {
    int32 e;
  } while (e > 0);
}
@TheModMaker TheModMaker added enhancement New feature or request language A new language feature labels Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language A new language feature
Projects
None yet
Development

No branches or pull requests

1 participant