Switch | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Switch

https://code.sololearn.com/cExgxEfg54gY/#cs Is it possible to go over from the case of the internal switch to the external switch?

3rd Jan 2020, 5:26 PM
Mary_d9
Mary_d9 - avatar
8 Answers
+ 2
Mary_d9 I was thinking about using a method, that can accept a string array (of choices), and return an int (the chosen option). Would it be a feasible option in your case?
3rd Jan 2020, 6:37 PM
Ipang
+ 2
Mary_d9 The method signature may look like this; int GetMenuChoice(string[] choices) In the method you display each array element on a different line. Then you ask the user to choose by entering a number which is valid amongst the choices. e.g. If the array has 5 elements, you can make the method to ask again if the user enters a number that is < 1 or is > 5. If the user enters a number between 1 and 5 the method will return the number. You know which choice was taken/chosen as you get this return value in the caller side. That's the idea, but I'm not sure if it is feasible for your project : )
3rd Jan 2020, 6:48 PM
Ipang
+ 1
you mean you need to use nested switch?
3rd Jan 2020, 5:41 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
nested switch are hard to manage, I think it would be better to use an if-statement with a do{} while. if you want to loop over and over.
3rd Jan 2020, 5:58 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
Mary_d9 Care to share about what or why the need to use nested `switch` statement?
3rd Jan 2020, 6:22 PM
Ipang
+ 1
Ipang I need to make a menu, and so that selecting one item, another menu opens
3rd Jan 2020, 6:24 PM
Mary_d9
Mary_d9 - avatar
+ 1
Ipang How to do it?
3rd Jan 2020, 6:40 PM
Mary_d9
Mary_d9 - avatar
3rd Jan 2020, 5:43 PM
Mary_d9
Mary_d9 - avatar