Imports System
Imports uCalcSoftware
Public Module Program
   
   Public Sub MyRepeat(ByVal cb As uCalc.Callback)
      Dim count = cb.ArgInt32(1)
      Dim action = cb.ArgExpr(2)
      Dim i = 0
      For i  = 1 To count
         action.Execute() '// Evaluate the expression on each iteration
      Next
   End Sub
   Public Sub Main()
      Dim uc As New uCalc()
      '// Define a counter variable in the engine
      uc.DefineVariable("counter = 0")
      
      '// The action 'counter++' is passed as an unevaluated expression
      uc.DefineFunction("Repeat(count As Int, ByExpr action)", AddressOf MyRepeat)
      
      '// Execute the custom loop
      uc.Eval("Repeat(5, counter++)")
      
      Console.Write("Final counter value: ")
      Console.WriteLine(uc.Eval("counter"))
   End Sub
End Module