Newb here working there way toward being a hobbyist.
My current project uses methods, classes, list to display books and comments and to allow users to enter their own comments in a console view. I've built my classes and they are working at this time so I've expunged them for the moment to expose my current problem as clearly as possible. get at my problem which is that I felt my program was getting kind of big quickly so it seemed like a good idea to move some of the code into a method which i called 'Select'. Before i moved the code into the select method, it worked fine/as expected. But now i'm getting error when i test: no enclosing loop out of which to break
The specific error happens on the else if (command == "e"){break;} line
I've tried swapping the keyword 'break' for 'continue', but that did not work. I've looked around the net and stackoverflow, but not found anything that i can understand well enough with my level of understanding to resolve (I'm still a newb).
Code:
class Program { public void Play(){ Announcer(" \n\nProgram Name Goes Here \n\n"); while (true) { /* * Allow user to display director of books (Three) * allow user to select specific book with any comments it might have (2-4 comments) * Allow user to enter a specific comment * display book with new new added comment * Allow user to exit book * */ Select(); Console.Read(); } } public void Announcer(String strTxt){Console.Write(strTxt);} public String GetString(String strData){ Console.WriteLine(strData); return Console.ReadLine();//traffic control => back to program } public void Select(){ String command = GetString(" \n\n(V)eiw, (S)elect, (C)omment, (R)emove, (E)xit").ToLower(); if (command == "v") { Announcer(" \n\nEnter listing: "); //ViewDirectory();//call view directory here } else if (command == "c") { Announcer(" \n\nEnter comment: "); } else if (command == "s") { //we want to do a selectString method that returns length of selects here String select = GetString(" \n\n(1)st Selection, (2)nd Selection, (3)rd book, (E)xit").ToLower(); if (select == "1") { Announcer(" \n\nDisplay book info + allow for user comment entering"); } else if (select == "2") { Announcer(" \n\nDisplay book info + allow for user comment entering"); } else if (select == "3") { Announcer(" \n\nDisplay book info + allow for user comment entering"); } } else if (command == "e") { break; } else { Console.WriteLine("\n\nOopsy, I don't know that command! \n\n"); } } } //public void ViewDirectory(){ // Console.WriteLine("stuff"); //}
boolfromSelectand base your loop on thatbool.