TodePond / DreamBerd

perfect programming language
https://dreamberd.computer
Other
11.49k stars 363 forks source link

Loops Possible using When Keyword #752

Open TheXJ-Github opened 1 month ago

TheXJ-Github commented 1 month ago

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 commented 1 month ago

technically these are repetitions, not loops, so its okay