uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026

Warning

uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.

Execute

Method

Product: 

Fast Math Parser

Class: 

Expression

Executes a pre-parsed expression without returning a value, optimized for operations valued for their side effects rather than their result.

Syntax

Execute()

Parameters

[None]

Return

void

This method does not return a value.

Remarks

The Execute method evaluates a pre-parsed Expression for its side effects, discarding any potential return value. It is the ideal choice for performance-critical loops or for running expressions that behave like imperative statements (e.g., variable assignments, increments) rather than mathematical calculations.

Execute vs. Evaluate

Choosing between Execute and Evaluate is a key architectural decision. Execute signals an intent to modify state, while Evaluate signals an intent to compute a value.

FeatureExecute()Evaluate() / EvaluateStr()
Return Valuevoid (None)A value (double, string, etc.)
PurposeFor side effects: changing variables, calling stateful functions.For computation: calculating a result.
PerformanceHigher. Bypasses the overhead of packaging and returning a value.Slightly lower. Incurs cost to prepare and return the result.
AnalogyA void function in C# or a statement ending in a semicolon.A function that returns a value.

⚖️ Comparative Analysis: Why uCalc?

In most programming languages, there is a clear distinction between an expression (which evaluates to a value, e.g., 2 + 2) and a statement (which performs an action, e.g., x = 5;). uCalc is primarily an expression engine.

The Execute() method provides a bridge, allowing you to treat a parsed expression as a statement. This is powerful because it lets you build script-like, imperative logic that runs within the high-performance, sandboxed uCalc environment.

  • Without Execute: To increment a variable in a loop, you would need to constantly read its value from the engine, perform the calculation in your host language (C#/C++), and write it back. This involves significant overhead from crossing the boundary between your code and the uCalc engine.
  • With Execute: You can define the entire operation (e.g., "x = x + 1") within a single parsed expression and call Execute() repeatedly. The entire loop runs inside the highly optimized engine, resulting in better performance.

Examples

How to perform a summation in a loop efficiently using Execute() instead of Evaluate().
				
					using uCalcSoftware;

var uc = new uCalc();
var VariableX = uc.DefineVariable("x = 0");
var Total = uc.DefineVariable("Total");
string Expression = "x++; Total = Total + x^2 + 5";

var ParsedExpr = uc.Parse(Expression);

for (double x = 1; x <= 10; x++) {
   // Execute() runs the parsed expression without the overhead of returning a value.
   // This provides near-native performance for loops across C#, VB, and C++.
   ParsedExpr.Execute();

   // Evaluate string interpolation to output the final calculated total
   Console.WriteLine(uc.EvalStr("$'{x}   Sub total = {Total}'"));
}

Console.WriteLine(uc.EvalStr("$'Total = {Total}'"));

ParsedExpr.Release();
VariableX.Release();
				
			
1   Sub total = 6
2   Sub total = 15
3   Sub total = 29
4   Sub total = 50
5   Sub total = 80
6   Sub total = 121
7   Sub total = 175
8   Sub total = 244
9   Sub total = 330
10   Sub total = 435
Total = 435
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto VariableX = uc.DefineVariable("x = 0");
   auto Total = uc.DefineVariable("Total");
   string Expression = "x++; Total = Total + x^2 + 5";

   auto ParsedExpr = uc.Parse(Expression);

   for (double x = 1; x <= 10; x++) {
      // Execute() runs the parsed expression without the overhead of returning a value.
      // This provides near-native performance for loops across C#, VB, and C++.
      ParsedExpr.Execute();

      // Evaluate string interpolation to output the final calculated total
      cout << uc.EvalStr("$'{x}   Sub total = {Total}'") << endl;
   }

   cout << uc.EvalStr("$'Total = {Total}'") << endl;

   ParsedExpr.Release();
   VariableX.Release();
}
				
			
1   Sub total = 6
2   Sub total = 15
3   Sub total = 29
4   Sub total = 50
5   Sub total = 80
6   Sub total = 121
7   Sub total = 175
8   Sub total = 244
9   Sub total = 330
10   Sub total = 435
Total = 435
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim VariableX = uc.DefineVariable("x = 0")
      Dim Total = uc.DefineVariable("Total")
      Dim Expression As String = "x++; Total = Total + x^2 + 5"
      
      Dim ParsedExpr = uc.Parse(Expression)
      
      For x  As Double = 1 To 10
         '// Execute() runs the parsed expression without the overhead of returning a value.
         '// This provides near-native performance for loops across C#, VB, and C++.
         ParsedExpr.Execute()
         
         '// Evaluate string interpolation to output the final calculated total
         Console.WriteLine(uc.EvalStr("$'{x}   Sub total = {Total}'"))
      Next
      
      Console.WriteLine(uc.EvalStr("$'Total = {Total}'"))
      
      ParsedExpr.Release()
      VariableX.Release()
   End Sub
End Module
				
			
1   Sub total = 6
2   Sub total = 15
3   Sub total = 29
4   Sub total = 50
5   Sub total = 80
6   Sub total = 121
7   Sub total = 175
8   Sub total = 244
9   Sub total = 330
10   Sub total = 435
Total = 435