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 Possible using When Keyword #752

Open
TheXJ-Github opened this issue Oct 5, 2024 · 1 comment
Open

Loops Possible using When Keyword #752

TheXJ-Github opened this issue Oct 5, 2024 · 1 comment

Comments

@TheXJ-Github
Copy link

The when keyword makes code run when a variable mutates.
So, using the functionality of said keyword, we can make it run code that mutates the variable which runs the code.

Here's an example implementation (with a limit so the code doesn't go haywire):

// Initiate our variable
var var i = -1!

// when i variable mutates, run the code block
when (i > -2) {
   // check if its less than 5
   if (i < 5) {
      // print i then add 1 to it
      print(i)!
      i = i + 1!
   }
}

// add 1 to i to initiate the loop
i = i + 1!

Unfortunately limiting the number of times when runs code when a variable mutates can cause some problem in code that uses it in the correct way.
So, how would you go about avoiding this kind of loop in DreamBerd?

@TodePond
Copy link
Owner

TodePond commented Oct 8, 2024

technically these are repetitions, not loops, so its okay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants