// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class LoopFun {
    private final static int REP = 2000000000;
    public static void test1() {
        long t1 = System.currentTimeMillis();
        SomeData sd = new SomeData(REP);
        for(int i = 0; i < sd.getN(); i++) {
            sd.add();
        }
        if(sd.getSum() != sd.getN()) {
            throw new RuntimeException("Ooops");
        }
        long t2 = System.currentTimeMillis();
        System.out.println("Keep in: " + (t2 - t1));
    }
    public static void test2() {
        long t1 = System.currentTimeMillis();
        SomeData sd = new SomeData(REP);
        int n = sd.getN();
        for(int i = 0; i < n; i++) {
            sd.add();
        }
        if(sd.getSum() != sd.getN()) {
            throw new RuntimeException("Ooops");
        }
        long t2 = System.currentTimeMillis();
        System.out.println("Move out: " + (t2 - t1));
    }
    public static void main(String[] args) {
        test1();
        test2();
        test1();
        test2();
        test1();
        test2();
    }
}

class SomeData {
    private int n;
    private int sum;
    public SomeData(int n) {
        this.n = n;
        sum = 0;
    }
    public void add() {
        sum++;
    }
    public int getN() {
        return n;
    }
    public int getSum() {
        return sum;
    }
}
