Recursive function for bubble sort I often see nested loops as a solution to the bubble sort, but my solution involves a recursive function. Is the following solution less efficient than the traditional method?
public static int[] BubbleSort(int[] arrayOfValues)
{
    var swapOccurred = false;
    
    for (var i = 0; i &lt; arrayOfValues.Length; i++)
    {
        if (i == arrayOfValues.Length - 1)
            continue;

        if (arrayOfValues[i] &gt; arrayOfValues[i + 1])
        {
            //swap values
            var current = arrayOfValues[i];
            var next = arrayOfValues[i + 1];
            
            arrayOfValues[i] = next;
            arrayOfValues[i + 1] = current;

            swapOccurred = true;
        }
    }

    if (swapOccurred)
    {
        // keep going until no further swaps are required:
        BubbleSort(arrayOfValues);
    }

    return arrayOfValues;
}
Less efficient? It consumes more stack space, which shouldn’t be a problem for any dataset where a bubble sort would be appropriate.
With the latest version of the c# compiler, tuple deconstruction will allow you to swap the values with a single line of code (although it will probably be slower).
On a side note, I’m not clear on why you have a separate continue instead of having a lower conditional check. It’s the same thing.
Not sure if you know this, but you are examining already sorted elements with your recursive call. An “efficient” bubble sort moves the end position back one cell after each cycle.
Update: I did some rough testing your implementation, and get a stack overflow a bit after 8k items. Sorting 8k random numbers without reducing the end point took ~.75 seconds, sorting with reducing the end point took ~.70 seconds. Much better than I expected.  Using Moch Yusup modification to use a more traditional structure the time for 8k items was approximately the same, but it took 116.8 seconds for 80k items.
So, performance wise, within the usable range, recursion was functionally identical, but due to stack overflow the usable range is limited.  OTOH, the usable range and &quot;not enough time to go get a cup of coffee&quot; range are fairly close.
Just for comparison, I tried using the standard List.Sort method, which took .0003681 seconds for 8k items, and .006 seconds for 80k items...