I have a block of code that repeats using a "for" loop, and each loop constructs a form to display some text. Some thing like the shorthand code below.
Main() { For (int x: x<=20; x++) { createform(string[x]); } } So for each loop a different string is passed to a method that will construct a form as below.
createform void (string input_) { ... code to build form and add a button "cancelbutton" form.text = intput_ .... form.cancelbutton.Click += // and I want this to cause the original loop to end.... } No I know I could use the button to make int x greater than 20 and that would end the loop, but I don't actually know what the max value will be as this is dynamic. Again I could work this out and do he same thing but it seems a bit "messy".
Is there a neater way to cause the button click to exit the loop. How about if the Createform method is in a separate class to main, does that make any difference?