how to maintain weight during pregnancy?

i am 20 lbs overweight

my previous pregnancy i gained 32 lbs and only lost 17 now i am pregnant again my dr advised me to only gain 15-20

can i continue going to the gym i was finally starting to lose weight then ended up pregnant lol