Here's a completely contrived example that gets to the gist of my comment. I store the "logic" of the nested If
as custom vertex properties, and simply follow the results, highlighting the appropriate edges. Clearly, code can use the results for control of flow, and that flow can be visualized with the graph. If you really wanted to do this kind of thing, packaging up some functions to parse your logic and create the graph/properties/query API would make sense.
ClearAll[gr, x, y, z]
Manipulate[
With[{x = x, y = y, z = z},
HighlightGraph[
gr, {a \[DirectedEdge] (res = ReleaseHold@PropertyValue[{gr, a}, "Logic"]),
res \[DirectedEdge]
ReleaseHold@PropertyValue[{gr, res}, "Logic"]}]], {x, {1, 2}}, {y, {1, 2}}, {z, {1, 2}},
Initialization :> {gr =
Graph[{Property[a, "Logic" -> Hold[If[x == 1, b, c]]],
Property[b, "Logic" -> Hold[If[y == 1, d, e, d]]],
Property[c, "Logic" -> Hold[If[z == 1, f, g, f]]], d, e, f,
g}, {a \[DirectedEdge] b, a \[DirectedEdge] c,
b \[DirectedEdge] d, b \[DirectedEdge] e, c \[DirectedEdge] f,
c \[DirectedEdge] g}, VertexLabels -> "Name"]}]
Graph
object in such a way, e.g., putting the "logic" in vertex/edge custom properties. But, you'd need to handle what MMA does with it (a simple parser), since on their own they have no meaning to MMA (they're custom, after all). I'd also suggest if nesting ofIf
is such it's confusing, a different control-of-flow construct, or a refactoring of code, might be in order. $\endgroup$