Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're basically writing a very simple state machine - use functions to represent every state: (I'll use random pseudocode, since you didn't specify a language)</p> <pre><code>get_information(): return get_record() ask_record(): record = read_line() return () if !record return ask_y(record) ask_x(record): x = read_line() return ask_record() if !x return ask_y(record, x) ask_y(record, x): y = read_line() return ask_x(record) if !y return ask_continue(record, x, y) ask_continue(record, x, y) continue = read_line() return ask_y(record, x) if !continue return (record, x, y) </code></pre> <p>this is a trivial approach. In some languages the call stack will grow, in others it won't. If you have a language which causes the stack to grow, you can use trampolines to prevent it, by rewriting <code>get_information</code> to do:</p> <pre><code>x = get_information while x is function: x=x() return x ask_x(record): x = read_line() return (lambda: ask_record()) if !x return (lambda: ask_y(record, x)) </code></pre> <p>Or even abstracting the question and memory address of result in some <code>question</code> structure:</p> <pre><code>struct question { question *next, *prev; char prompt[]; char **result; } </code></pre> <p>and then running in a loop, calling <code>question* run_question(question*)</code>, going to ->next, or ->prev depending on the answer, until the result is NULL (as a stop condition, when results are filled in and no questions are left).</p> <p>The last solution is probably the most "normal one" if you use an imperative language with direct pointer access.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload