I disagree with Hooked. Flow charts, with some restrictions (using loops is NOT one of them), are planar. Some examples:
- A single primitive command translates to a planar graph (a single node)
- A sequence of statements: if the statements can be translated to planar graphs, the sequence can itself be translated to a planar graph (simply by connecting those subgraphs)
- A function: the same as above
- A (
repeat-until
, while-do
, etc) loop is a sequence of statements that forms a cycle. Cycles are fine too, as long as they properly nest (and such constructs are designed to properly nest).
- Goto statements (
goto
, or break
/continue
/return
statements that may jump) are not ok. If you have a nested loop, and from inside that you jump out of the outer loop, such an edge would clearly intersect the cycle (loop, function) that contains it. If the code is translated to exit one loop at a time, these are fine too. (This translation is not too different from simply introducing nodes to model the intersections).
There must be a more systematic way to formally prove that a flow-chart deriving from compositions of a particular set of constructs is planar, I wish I could think of it in 5 minutes, but no luck :)
update: By the way, goto
s can trivially create a K3,3 or K5, for example this is a K5 (in good old-fashioned QBasic!):
00 GOTO (INT(RND * 5) * 10)
10 GOTO (INT(RND * 5) * 10)
20 GOTO (INT(RND * 5) * 10)
30 GOTO (INT(RND * 5) * 10)
40 GOTO (INT(RND * 5) * 10)