Loop for inserting a node into a binary search tree
(Just checking - you want your BST to be allowed to contain duplicates? That's what your current code does.)

Edit: After fixing some mistakes kindly pointed out by @vnp, here is an implementation of insert:

    public void insert(int n) {
        final boolean RIGHT = true;
        final boolean LEFT = false;

        node previousNode = null;
        boolean previousDirection = LEFT; // arbitrary
        node currentNode = head;

        while (currentNode != null) {
            previousNode = currentNode;
            if (n &gt; currentNode.data) {
                currentNode = currentNode.right;
                previousDirection = RIGHT;
            } else {
                currentNode = currentNode.left;
                previousDirection = LEFT;
            }
        }

        if (previousNode == null) {
            head = new node(n);
        } else if (previousDirection == LEFT) {
            previousNode.left = new node(n);
        } else {
            previousNode.right = new node(n);
        }
    }


This avoids using while(true) and break; and uses more shallow if statements, which I think makes it marginally easier to follow.