title: Sorting using a while loop and a for loop?
body: <p>My first programming lab is to do a sorting algorithm to sort a character array. I've successfully do it using two for loops, but in order to improve my skills, I want to know if there's a way to do it using a while loop and a for loop?</p>
  
  <pre><code>//Include any needed libraries
   #include &lt;iostream&gt;
   #include &lt;algorithm&gt;
   #include &lt;iterator&gt;
  
  //Specify the standard namespace
  using namespace std;
  
  int main(){
  //Initializes variables.
  
  char foo[7] = {'a','c','g','j','a','c','d'};
  //char foo[7];
  bool sorted =false;
  int i = 0;
  int j = 0;
  char temp;
  
  //Print out the pre-sorting array. 
  cout &lt;&lt; "The array before sorting is: ";
  for (int i=0; i&lt;7; i++){
      cout &lt;&lt; foo[i];
  }
  cout &lt;&lt; endl;
  
  
  
  //The swap function. 
      for(i=0;i&lt;7;i++){
          for (j=0; j&lt;7;j++){
              if(foo[i]&lt;foo[j]){
                  temp = foo[i];              
                  foo[i] = foo[j];
                  foo[j] = temp;
              }
          }
      }
  }
  
  cout &lt;&lt; "The array after sorting is: ";
  for (int i=0; i&lt;7; i++){
      cout &lt;&lt; foo[i];
  }
  
  cout &lt;&lt; endl;
  
  
  return 0;
  } 
  </code></pre>
  
  <hr>
  
  <p>EDIT: Here's a psuedocode written by our TA: </p>
  
  <pre><code>array[];
  bool sorted = false;
  while(!sorted){
     sorted = true;
     for each element{
        compare
        swap
     if swapped: sorted = false
  }
  </code></pre>
  
  <p>So what I really wanted to know is how to I integrate boolean statements in the while loop?</p>