Q:

Implementing an algorithm with repeat/until using Java

Help me simulate this algorithm:

Given the array [5 3 1 9 8 2 4 7], assume that l = 0.
I converted it to code:
public class Test {

public static void main(String[] args) {
    int[] a = {5,3,1,9,8,2,4,7};
    int l = 0;
    int p = a[l];

    int i=l;

    int j = 8;
    do{
        do{
            i++;
            System.out.println("Value of i " + i);

        }while(a[i]>=p);
        do{
            j--;
            System.out.println("\nValue of j " + j);

        }while(a[j]<p);
        swap(a,i,j);
        System.out.println("\nSwapped! a[i] = " + a[i] + " a[j] = " + a[j]);
        System.out.println("Swap 1");
        for(int k : a){
            System.out.print(k + " ");

        }

    }while(i>=j);
    if(i>=j){
        swap(a,i,j);
        System.out.println("\nSwapped! a[i] = " + a[i] + " a[j] = " + a[j]);
        System.out.println("Swap 2");
        for(int k : a){
            System.out.print(k + " ");

        }
    }
    else{
        swap(a,i,j);
        System.out.println("\nSwapped! a[i] = " + a[i] + " a[j] = " + a[j]);
        System.out.println("Swap 3");
        for(int k : a){
            System.out.print(k + " ");

        }
        swap(a,l,j);
        System.out.println("\nSwapped! a[l] = " + a[l] + " a[j] = " + a[j]);
        System.out.println("Swap 4");
        for(int k : a){
            System.out.print(k + " ");

        }

    }

    System.out.println("\nreturn value is: " + j);

    System.out.println("Final array: ");
    for(int k : a){
        System.out.print(k + " ");
    }

}

public static  void swap(int a[], int a1, int a2){
    int temp = a[a1];
    a[a1] = a[a2];
    a[a2] = temp;
}

}

The result is:

But when I simulate it in paper, my results are different. It's either I mistook "repeat until" with "do while" or I wrongly analyzed in paper.
Share me your simulations mates :) Thank you!

A:

It's either I mistaken repeat until for do while or I wrongly analyzed in paper.

You did translate repeat/until incorrectly.
The construct comes from Pascal-like languages. It is similar to do/while, but the meaning of the condition is completely opposite: in do/while the condition at the end is continuation condition, but in repeat/until the condition is the termination condition.
The fix for this problem is inverting the conditions of repeat/until loops:
do{
    i++;
    System.out.println("Value of i " + i);
} while(a[i]< p);
//          ^

