using uCalcSoftware; var uc = new uCalc(); static void MyRepeat(uCalc.Callback cb) { var count = cb.ArgInt32(1); var action = cb.ArgExpr(2); var i = 0; for ( i = 1; i <= count; i++) { action.Execute(); // Evaluate the expression on each iteration } } // 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)", MyRepeat); // Execute the custom loop uc.Eval("Repeat(5, counter++)"); Console.Write("Final counter value: "); Console.WriteLine(uc.Eval("counter"));