This code is part of a program that jumbles a word. I need help understanding how the for loop is working and creating the jumbled word. For example if theWord = "apple" the output would be something like: plpea. So I want to know whats going on in the for loop to make this output.
    std::string jumble = theWord;
    int length = theWord.size();
    for (int i = 0; i < length; i++)
    {
        int index1 = (rand() % length);
        int index2 = (rand() % length);
        char temp = jumble[index1];
        jumble[index1] = jumble[index2];
        jumble[index2] = temp;
    }
    std::cout << jumble << std::endl;
 
    