Discussion about Emotion Detector Practice run | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Discussion about Emotion Detector Practice run

Hi guys, its Serana here. Today is ironically my first time using a switch statement despite my full years worth of classes learning Java. I'd never went over it, but, interestingly, I picked up a few tid bits on the way a switch statement functions. Whilst running my code I neglected the break function on cases 3 and 4 and realized that all the other cases ran just fine but I had cultivated errors for cases 4 and 5. (on the results screen, not the code) Correct me if im wrong, but I'm very fuzzy on how a break statement actually works but I would like to atleast inform those who are just as in the dark as I am, so if you want to see more, peek into the comments for my added dialogue.

13th Jan 2021, 12:47 AM
Serana Zentha
Serana Zentha - avatar
6 Answers
+ 1
Serana Zentha Thanks for your help. But there is an easier way than this. You can always help other people by giving answers directly in their questions here in Q&A Forum. Or you can make a lessons like this via Code Bits.
13th Jan 2021, 12:59 AM
noteve
noteve - avatar
+ 2
Serana Zentha I understand why you post this in Q&A Forum, it is because of the word "Discuss" that can be misleading for most people. However, in fact, this place is only for programming-related questions. If you have errors or bugs in your code, you can always ask for help here by showing your attempt code. You can post this on your feed instead. Thanks and Happy Coding! 👍 https://www.sololearn.com/Discuss/1316935/?ref=app
13th Jan 2021, 12:52 AM
noteve
noteve - avatar
+ 1
《 Nicko12 》 sorry, I thought this would be a nice place for people to find out what error they made in their code. Ill try to do it on my feed next time
13th Jan 2021, 12:57 AM
Serana Zentha
Serana Zentha - avatar
0
Switch statements are a good way of running a specific version of an if statement if your desired result is to have the program run faster, like if you are creating a game. One of the functions within this statement are the Default and Break functions. A Default is used when none of the case statements are met, but what I want to talk about today are Break functions. If you read above, you probably know what specifically about a break statement I want to discuss, and thats what happens in a Switch statement when few or none of the Case statements have a Break. When a Case statement is mossing a break, it will function as if it were a small if statement and if the case is met, it will execute the given code. However, if the Case statement is missing a Break function, it will run as if it were an If statement and continue to check the other Cases, as well as run Default if the other Case statements are not met, which is why you are possibly getting an error in some of your results Cases
13th Jan 2021, 12:53 AM
Serana Zentha
Serana Zentha - avatar
0
If you are having this problem, check to see if you are Breaking your Cases, or else it will print whatever is in Default for every case missing the break statement, as well as the correct Case that matches.
13th Jan 2021, 12:55 AM
Serana Zentha
Serana Zentha - avatar
0
Mirielle I should have been more specific and said loop, I just forgot the associated word. But thanks for the clarification, I'm glad I was at least informative in the continuation of the loop in the abscence of "Break"
13th Jan 2021, 12:59 AM
Serana Zentha
Serana Zentha - avatar