It depends on the production and how the network canceled the show.
You only have to have three or four episodes completed prior to broadcast, so I'm sure in some cases, but not all, depending on how early or late the show is canceled, they may cease production altogether, or if the series is canceled later, they may have already finished the production season, such as GREG THE BUNNY, it was canceled before the last three episodes aired.
It's my understand that HOGAN'S HEROES was in the process of starting production on a seventh season, and it was supposedly going to be the proper final season, but the show got caught up in the Rural Purge, and as such, was canceled before they started production on that season.
Similarly, I DREAM OF JEANNIE went back and forth: there were talks of canceling the series after its fifth season, so the producers did a final episode where Dr. Bellows finally learns the truth about Jeannie (and appropriately, it was a flashback episode), but then the network changed its mind and decided to renew it for a sixth season, so the episode was changed to where Dr. Bellows learning the truth was all a dream that Tony had... THEN, after that episode was completed and in the can, the network changed its mind again, and canceled the show after all.
And, on that same token, M*A*S*H did so poorly in its first season, that the producers were concerned they wouldn't be renewed for another season, so an alternate version of the episode "Ceasefire" was written where the ceasefire WAS real, and the war DID end, in case they weren't renewed for a second season... but like THE ODD COUPLE, summer reruns saved them, and it went on to be one of the longest running sitcoms there was.