<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Maybe I'm stating the obvious, but if you don't want to change the
    code, then you need to define the branching logic and
    questions/answers as data and write an "engine" that processes the
    data and decides what question is next based on the current state
    (e.g., the answer to the current question, and possibly other
    information relevant to your application). You should beware that
    this could become icky. For example, it may be possible to create
    bugs in the branching logic.<br>
    <br>
    I don't know what the context is, but I believe what you're
    describing is called "skip logic" and "branching" in the survey
    industry and it's implemented in packages like LimeSurvey: 
<a class="moz-txt-link-freetext" href="https://www.limesurvey.org/blog/20-blog/129-skip-logic-and-branching-equip-your-survey-structure-with-intelligent-paths">https://www.limesurvey.org/blog/20-blog/129-skip-logic-and-branching-equip-your-survey-structure-with-intelligent-paths</a><br>
    <br>
    Even if you cannot use Lime Survey, you might look at how they
    implement the rules and think about how you would build an engine to
    implement this yourself. <b>I think in essence</b>, each question
    has an ID and the survey has a sequence. Each item either has skip
    logic, or doesn't. If skip logic exists for a question, then each
    response to the question needs a ID to branch to. If not, the next
    question in the survey sequence is chosen. It wouldn't be a
    monumental task to write this kind of simple engine. I guess
    implicit in this is that you should be reading your questions and
    answers from some kind of human- and machine-readable format like
    YAML or JSON. This file is where you would insert the skip logic in
    a format you devise. I found references to XPDL in googling as
    described below. You should define as much complexity as you need. I
    had a student who couldn't use SurveyMonkey because he wanted to
    administer a six-item depression survey, score it, and then branch
    based on whether the score indicated depression or not. At the time,
    scoring survey questions and adding them up was beyond what SM could
    do. He found that Qualtrics did have a feature to do this.<br>
    <br>
    Implicit in my description above is that the main purpose is to
    collect and store survey responses. If your goal is more like
    reaching a decision (e.g., "Based on your responses, an
    adjustable-rate mortgage would best suit your needs...") then the
    questions AND the ending decisions have to be part of the data and
    perhaps the logic isn't as simple as above (maybe there is no
    sequence and every question needs a branch, or there are sections of
    questions that go together and branch between sections). It looks
    like XPDL is an industry standard (in the workflow industry)  for
    representing this.<br>
    <br>
    If you google "decision tree" you get a bunch of hits for machine
    learning. I googled "Perl decision process tree" and that lead me to
    potentially useful articles like the one below, in which someone
    wants to create flexible rules about "workflow" (how how tickets are
    routed in a ticketing app):
    <a class="moz-txt-link-freetext" href="https://www.perlmonks.org/?node_id=222257">https://www.perlmonks.org/?node_id=222257</a><br>
    <br>
    This is also similar to the way web frameworks work. But I think
    there you'd be writing code to perform each step, so that's probably
    not helpful.<br>
    <br>
    I am continually amazed by what's on CPAN but I doubt you will find
    a module for anything like skip logic/workflow in abstract. I think
    it's more likely to be embedded in a context, like the ticketing
    app, a survey, or a web frame work. But it looks like there are some
    Perl modules for implementing workfows. <br>
    <br>
    -Alan<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 2/6/2021 8:53 AM, Richard Reina
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAKLxnzYmHZq_EXBxCbV87vLsZ=0eXv2s8GNMnqxxRZQMrB=FSg@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">I am trying to write code that would guide a user
        through a series of questions and depending on their answers
        given ask them different questions. I can of course do this with
        procedural code but it has occured to me that it might begin to
        get messy especially when exceptions mount. For example, if the
        answer to the third question is no, then skip to question 8. So
        I am looking for a way to structure such code to make it cleaner
        and perhaps easier to maintain, Does anyone know of any examples
        of similar projects that I can reference?
        <div><br>
        </div>
        <div>Thanks,</div>
        <div><br>
        </div>
        <div>Richard </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Chicago-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a>
<a class="moz-txt-link-freetext" href="https://mail.pm.org/mailman/listinfo/chicago-talk">https://mail.pm.org/mailman/listinfo/chicago-talk</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 

Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.

science + technology = better workers

<a class="moz-txt-link-freetext" href="http://www.alanmead.org">http://www.alanmead.org</a>

The irony of this ... is that the Internet is
both almost-infinitely expandable, while at the
same time constrained within its own pre-defined
box. And if that makes no sense to you, just
reflect on the existence of Facebook. We have
the vastness of the internet and yet billions
of people decided to spend most of them time
within a horribly designed, fake-news emporium
of a website that sucks every possible piece of
personal information out of you so it can sell it
to others. And they see nothing wrong with that.

-- Kieren McCarthy, commenting on why we are not 
                    all using IPv6
</pre>
  </body>
</html>