Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

In lecture 3, I saw a piece of code, if return else return else return I've done a bit of programing before, and have always done: int a=0 if(bla bla bla) a=1 else(bla bla bla) a=2 else(bla bla bla) a=0 return a; Is my style of code (ignore the bad formatting) less readable, I.E bad code hygiene?

OpenStudy (anonymous):

Are you asking "Is it better to just return a value or to set that value to a variable and then return it at the end?" I'd say in general it doesn't matter, though if there's no real reason to introduce a variable, then why bother doing so? Not having to keep track of that variable makes the code a tiny bit easier to understand. (You can't use multiple else statements in Python, by the way. I think you mean if, elif, and else.)

OpenStudy (anonymous):

Thanks for the answer. Sorry about the, else, else, I just wrote up a quick piece of pseudocode

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
HeyItsAlicia: Why was questioncove not working??
4 hours ago 2 Replies 1 Medal
Countless7Echos: Ah trying out the whole T.V girl drawing :p (I love drawing eyes)
14 hours ago 14 Replies 6 Medals
kaelynw: starting to draw a hand
3 days ago 17 Replies 2 Medals
Twaylor: Rate it :D (Took 2 days)
6 days ago 7 Replies 0 Medals
XShawtyX: Art, Short Writing Assignment: Imagining Landscapes
2 days ago 9 Replies 1 Medal
XShawtyX: Chemistry, Help ud83dude4fud83cudffe
1 week ago 13 Replies 1 Medal
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!