Doubt in video pls help

sir in this video “return dp[n]=ways” is written outside the for loop , is this right or we have to write this inside for loop ???

this is a more optimised way
u can do both the ways
which ever u feel more comfortable in

when u do a lot of q
then u feel that why write 2 lines when thing can be done in 1