There are several ways to do this depending on the types of transitions expected and sampling requirements. These assume no sampling clocks.
module top;
class A;
bit [3:0] temp;
task run;
fork
forever #10 temp++;
begin // if you know the order
wait(temp==1);
$display("temp==1");
wait(temp==2);
$display("temp==2");
end
begin // if you don't know the order
bit [3:0] temp_last;
forever @(temp)
if (temp_last == 1 & temp == 2)
begin
$display("1 -> 2");
break;
end
else
temp_last = temp;
end
join_any
#1 disable fork;
endtask
endclass
A h;
initial begin
h = new;
h.run();
end
endmodule