I haven't done this thing you are asking about, but if I did here is the approach I would take. First, you have to map out all of the possible paths of logic. So you would have sets of questions and to each of those questions a set of possible responses. Then to each of those responses new sets of questions. So, this would logically create a graph of sets of possible questions and their possible responses. I would codify this relationship as Question and Response objects. Also, you would need to define some way with the Response object to indicate what to do next (either point to a new set of Questions, or it is complete). So, following that line of thinking you would wind up with a graph, or more precisely, a tree structure. And it could be iterated simply like this using a Stack:
// need to pull the Initial Set of Questions to start
List<Question> currentQuestions = GetInitalQuestions();
// a stack to track the chosen responses, so we can unwind if needed
Stack<Response> responseStack = new Stack<Response>();
// out exit condition is when currentQuestions is null
while(currentQuestions != null)
{
// display the questions and get the user's response
Response resp = DisplayQuestions(currentQuestions);
// if we need to back up...
if (resp == Response.Back)
{
// make sure we have something to fall back to...
if (responseStack.Count > 0)
resp = responseStack.Pop();
else
HandleAtBeginningOfStack();
}
else
{
// add the chosen response to the stack
responseStack.Push(resp);
}
// get the next set of questions based on the response, unless we are at the end
if (resp.IsFinal)
currentQuestions = null;
else
currentQuestions = GetQuestionSetFromResponse(resp);
}
With this being the underlying logic, you would need to construct a UI to present the Questions and Responses. I would create a Form with a single Panel. On the form have a method called DrawPanel, or something like that, when passed a set of Questions and their responses it would clear the Panel and draw the necessary controls. So, it would dynamically create the display as the questions and responses are chosed by the user. Since we have a Stack of the chosen responses you could use it somewhere on the form to display to the user the options they have previously selected.