Click to See Complete Forum and Search --> : do while problem


salem99
07-07-2004, 12:15 PM
hi
i have a problem with do while in this code


public int find (int value)
{

int counter = 0;
Node tempNode = root;

do {

counter++;
if (value == tempNode.getValue() )
{
this.current = tempNode;
return counter;
}
else if (value < tempNode.getValue() )
{
tempNode = tempNode.getLeft();
//this.current = tempNode;
}
else
{
tempNode = tempNode.getRight();
//this.current = tempNode;
}
}
//current = null;
return -1 * counter;
} while (tempNode != null);

its not running and i am confused where is the problem here.

thanx

Drain
07-07-2004, 12:54 PM
You have the while outside the method brackets, instead of the do brackets. Do you not indent your code or something? It should have been obvious when you looked at it.

public int find (int value)
{
int counter = 0;
Node tempNode = root;

do {
counter++;
if (value == tempNode.getValue() )
{
this.current = tempNode;
return counter;
}
else if (value < tempNode.getValue() )
{
tempNode = tempNode.getLeft();
//this.current = tempNode;
}
else
{
tempNode = tempNode.getRight();
//this.current = tempNode;
}
}
//current = null;
return -1 * counter;
} while (tempNode != null);

This is what you have :eek: