Is "case:" works like instruction "goto:" ( label) in i.e. Pascal? It allows to omit some part of code. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is "case:" works like instruction "goto:" ( label) in i.e. Pascal? It allows to omit some part of code.

I didnt finish C++ course but I would like to know have I good intuition. I realized that case works only with "switch". Lack of "break" gives me that remark.

6th Dec 2016, 12:08 AM
Jack
Jack - avatar
2 Answers
+ 2
Nope, case is not an analog of goto. Just forget about goto, consider it was a bad dream))) Generally, switch-case (and yes, case statement is used only inside switch statement) is a more convenient way to handle multiple if-elseif-...-else statements, but just for 1 integer variable (for c++, in js you can pass strings, floats or whatever). Also, it could be used for some custom behavior, but this comes with experience.
6th Dec 2016, 12:19 AM
Demeth
Demeth - avatar
+ 1
Thank you. "Goto" was usefull in Assembler where lines had numbers (10, 20, 30 and so on). My old habit...
6th Dec 2016, 12:20 PM
Jack
Jack - avatar