Is there a way to avoid loops to make this code faster ?

"var" is the desired result.

"AA" and "BB" are vectors whose values are known.

The four principal lines of this code are based on the logic: `00`,`01`,`10`,`11` ( `0` for `<=` and `1` for `>` )

```
for i=3:1:2000

    for j=1:50011
        if AA(i) == j && BB(i)<=BB(i-1) && BB(i-1)<=BB(i-2)
           var(i)=j;
        else
            if AA(i) == j && BB(i)<=BB(i-1) && BB(i-1)>BB(i-2)
               var(i)=j+50011;
            else
                if AA(i) == j && BB(i)>BB(i-1) && BB(i-1)<=BB(i-2)
                   var(i)=j+2*50011;
                else
                    if AA(i) == j && BB(i)>BB(i-1) && BB(i-1)>BB(i-2)
                       var(i)=j+3*50011;
                    end
                end
            end
        end
    end

end

```