0

Are they the same? If so, which one is preferred by the more advance programmer and why?

Thanks,
Scott

2
Contributors
3
Replies
4
Views
12 Years
Discussion Span
Last Post by Dogtree
0

>> Are they the same?
Kinda sorta, but not really. A switch is a control flow structure that directs execution through a certain block of code depending on an integral value. In other words, it's like door #1, door #2, and door #3 in the old gameshows. Those three doors together would be the body of a switch, 1, 2, and 3 would be the cases, and the condition is the very confused contestant trying to pick which one to open.

A function is a named block of code that can optionally accept data to work with and optionally return data when it's done. Think of a function like a drive through carwash. The carwash is the function, a dirty car going in is an argument, the body of the function cleans the car, and a clean car coming out is the return value.

0

Thanks Dogtree.. Let me know. If you were to do a multiple choice question, which would you use. Switch or Function?

Scott

0

Anytime you need to split off into one or more separate paths, you're looking at a switch or if chain.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.