Why that complicated, use a variable to sum up the count of deleted rows and let the WHIL loop end when the sum exceed the BatchMaxRowCount
DECLARE @BatchSize INT = 20000
, @BatchMaxRowCount INT = 300000;
DECLARE @counter int = 0
WHILE @BatchMaxRowCount >= @counter
BEGIN
DELETE TOP (@BatchSize) FROM dbo.MyTable;
SET @counter = @counter + @@ROWCOUNT;
END