SALEM – A Lynn man who admitted stealing $20 from an undercover narcotics officer as he swung a rock inside a sock at him last year is headed to state prison for up to four years.In Salem Superior Court Monday, David M. Lane, 44, who last lived at 23 Acorn St., #1, opted to avoid a jury trial and pleaded guilty to a charge of armed robbery.Judge David A. Lowy sentenced him to serve not less than three years and not more than four years in state prison.In handing down the punishment, Lowy said he felt it was reasonable, given the case.On the late afternoon of Sept. 1, the Lynn police narcotics unit was working undercover in the Washington Street area. An undercover officer offered to buy crack cocaine from Lane for $40 as he was walking down Washington Street. Lane took the money, but could not produce any crack cocaine. When the undercover officer demanded the cash back, Lane only gave him $20 and refused to give him anymore. Lane then swung a sock holding a rock inside at the officer as he fled from the scene.An undercover officer observing the incident did not move in and arrest Lane at that time. He was arrested the following month on an indictment warrant.Assistant District Attorney A.J. Camelio, who was seeking a three-to-seven-year sentence, said it was based on the facts of the case as he pointed to his long criminal history, which includes violence, larceny and assault and battery crimes, he said.But defense lawyer Rebecca Whitehill pointed out to Lowy that one-half of Lanes’ record included dismissals and dropped cases and others involved drinking in public and trespassing, emphasizing that it is “not that serious of a record.”She said Lane is the father of four children and has a “long term drug history,” while noting he had some years of sobriety as she asked for a two-year prison term.The judge agreed to credit Lane the 174 days he spent in jail awaiting trial on the case.