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?
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):
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?