How to enter while loop on a posedge of a trigger?

I want a while loop to enter on a posedge of a trigger.
Below options are giving syntax error.

task mytask()
      while( posedge(my_if.trigger)) begin
        :
        :
      end //while
endtask
task mytask()
      while( posedge(my_if.trigger)==1) begin
        :
        :
      end //while
endtask

It should be pretty simple. I tried using while(@ posedge (my_if.trigger))
All are giving syntax error. I tried searching and didn’t find any code that I needed. Any clue what am I doing wrong?

In reply to sdesai:

Your description is not very clear. If you want to wait for a posege of trigger that would be

task mytask()
      @( posedge my_if.trigger )
        :
        :
endtask

If you want a loop that begins at every posedge, that would be

task mytask()
      forever @( posedge my_if.trigger) begin
        :
        :
      end
endtask

You would need to explain what, if anything, needs to happen to get out of the loop.

In reply to dave_59:

Thanks Dave!
I think, your first example would work in my case.
I want to wait for this variable to be triggered before executing the rest of the task. I don’t want to do a level check.
I have used this several times in the past. But was thinking to use a while loop. I think the above solves the purpose. Thank you!