Sorting an array in C++ using Bubble sort
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);
}