Loop for inserting a node into a binary search tree I am trying to implement binary search tree. One method which I am trying to implement in the most efficient and stylish way is node insertion.
I am under the impression that  while (true) is a bad practice, correct?

    while (true){
        if(n &lt;currentNode.data){
            if (currentNode.left == null){
                currentNode.left = new node(n);
                break;
            }else{
                currentNode = currentNode.left;
            }
        }else 
            if (currentNode.right == null) {
                currentNode.right = new node(n);
                break;
            } else{
                currentNode = currentNode.right;
            }
    }


and here is the whole code:

package graph;

public class BSearchTree {
    private node head = null;
    public BSearchTree(int [] entries){
        for (int a : entries){
            insert(a);
        }
    }
    public void insert(int n){
        if (head == null){
            head = new node(n);
            return;
        }
        node currentNode = head;
        while (true){
            if(n &lt;currentNode.data){
                if (currentNode.left == null){
                    currentNode.left = new node(n);
                    break;
                }else{
                    currentNode = currentNode.left;
                }
            }else 
                if (currentNode.right == null) {
                    currentNode.right = new node(n);
                    break;
                } else{
                    currentNode = currentNode.right;
                }
        }

    }

    public static void main(String[] args) {
        BSearchTree bst = new BSearchTree(new int[]{2,4,1,5});  
        System.out.println(bst.toString());
    }


    private class node {
        int data = -1;
        node left = null;
        node right = null;

        public node(int n){
            data = n;
        }
    }
}
(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.