So far as I’m aware (and I hope I’m right, 'cause this is how I do it!), you just knit or purl according to the pattern, casting off as normal as you go. OK, I realise that isn’t very clear, so here’s what I mean.
Assuming your row starts K2, you would cast off as follows:
K2, pass 1st stich over second (1 stich cast off, one left on right needle),
P1 (this would have been the third stitch in the row and therefore a purl, assuming your pattern is K2, P2 rib) (there are now 2 sts on right needle), pass 1st st over 2nd (another 1 st cast off),
P1 (this would have been the 4th st int he row and therefore a purl, as above) (there are now 2 sts on the right needle again), pass 1st st over 2nd (another 1 st cast off)
K1 (this was the 5th st, so you’re back to K) (again, there are 2 sts on the right needle…
and so on.
Basically, you always work stitches before you cast them off, and you can work them in either knit or purl, as required by the pattern. You simply cast one stitch off every time you get two stitches onto the right hand needle.
I would also recommend that you go to the ‘View Videos’ section on this site. Go to the ‘Casting off’ section and look at the videos showing ‘basic knit bind-off’, ‘basic purl bind-off’, and ‘binding off “In Pattern”’ (this last shows casting off in a K1, P1 rib, rather than K2, P2, and it is perhaps just a bit too short, but I think you’ll get the idea).
Good luck! I’m sure you’ll be fine.