Simplify the procedure using the following trick. Extend the array val, adding a cell with index null. Let val [null] be t.
if t < val [x] then begin
x := left [x];
end else begin x := right [x]; end ;
end ; ..answer is (x <> null).