I think you have to win to get the candy, at least that's how the announcement reads:
"Finally, when you're successful in a raid, you're guaranteed to receive a Rare Candy, and whether you win or lose, you'll earn 3,000 Stardust—six times the usual amount"
But it it may be worth using that tactic for the stardust if you can get 3K every time.