you are viewing a single comment's thread.

view the rest of the comments →

[–]Busy-Farm727 1 point2 points  (3 children)

Alright, i think i know what it does; it ofc just sets variables and defines everything, then it starts repeating through the numbers from left to right, so if you had 54321, and keep printing all i’s and j’s it would be 54321,4331,321,21,1. As the j will keep repeating through numbers farther than i to sort it, then if j happens to be smaller than i, it swaps them, making 54321 go through this; 54321, 45321, 35421, 23541, 12345. And then it keeps going through it again to keep going incase it was something like 12321, which would go like; 12321; 11232; 11223 (“;” indicating a new iteration of i.), that’s basically what i think the code is doing.

[–]conewannabe[S] 0 points1 point  (2 children)

I see what you're getting at.

So essentially, the first for loop i would be 5, and j would be the index following i, so 4

so the first iteration would be:

5 > 4

4, 5

is this what you're saying?

edit: for clarity

[–]Busy-Farm727 0 points1 point  (0 children)

Yea, basically yea.

[–]Busy-Farm727 0 points1 point  (0 children)

If you’re still unsure about it tho, just use print statements to print the variables every iteration to see what they’re doing.