While working on the project, I noticed that Chloe was having some trouble programming. She was trying to figure out if it was better to use many if else statements or a switch. I couldn't help, because I have forgotten everything from last year in programming and wasn't very good at it in the first place. I had no idea why and how to use the switch or else statements. To find out more, I researched switch vs if-else statements. I found an article on GeeksforGeeks called switch vs if else. According to the article, determining which to use is based on what your testing and how easy it is to read. The article also gave a list of tips to check that will help you determine which is better. The first is to check the expression that you are testing for. Switch statements are used for expressions with a single value or a string object. The if-else statement is used for condition or value ranges. The second tip is to know if you want to do multi-way branching or not because switch statements are better for that. The third tip is to figure out if you have boolean values. If-else statements are better for boolean values, while switch statements are better for data values that are already put in place. The fourth time is to determine whether or not you want your code to run fast or slow. Switch statements are sometimes faster than if-else statements; however, it really depends on the number of cases involved. The last tip is to remember that precision is in readability. Switches are cleaner than if-else statements and it is easier to avoid errors with them. According to the article, you should pick whatever gives you a clearer and more attainable design. Tips to remember:
Works Cited “Switch vs If Else.” GeeksforGeeks, 20 May 2017, www.geeksforgeeks.org/switch-vs-else/.
0 Comments
Leave a Reply. |
AuthorI'm a student at Durham School of the Arts, and currently in the Game Art Design pathway. I like playing the Sims 4, playing with dogs, and riding horses. This blog will reflect my learning and discoveries. Archives
May 2019
Categories
All
|