Sorting an array in C++ using Bubble sort Here is my bubble sort algorithm that I would like to improve in any way possible
#include&lt;iostream&gt;

int main(){
    int arr[6] = {5,2,3,7,2,6};
    int f = 0;
    int b = 0;
    for(int i = 1;i &lt; 6;i++){
        if(arr[i] &lt; arr[i-1]){
            f = arr[i];
            b = arr[i-1];
            arr[i] = b;
            arr[i-1] = f;
            i=1;
        }

    }
    for(int i = 0;i &lt; 6;i++) std::cout &lt;&lt; arr[i] &lt;&lt; &quot; &quot;;
}


Anything is appreciated
Some notes:

I would avoid running a loop while changing i inside, it is very unclear to the reader. I prefer using two nested loops.
The swap can be done in one step less
I would initialize a size variable and use it throughout the code instead of hard-coding 6.
Printing the array to the console should be in a separate function (as well as the sorting function really).

#include&lt;iostream&gt;

int main(){
    const int sz = 6;
    int arr[sz] = {5,2,3,7,2,6};
    do{
        swapped = false;
        for(int i = 1;i &lt; sz; i++){
            if(arr[i] &lt; arr[i-1]){
                int tmp = arr[i];
                arr[i] = arr[i-1];
                arr[i-1] = tmp;
                swapped = true;
            }
        }
    } while(swapped);
    print_array(arr, sz);
}