If-Else Flow-chart Question

This is a discussion on If-Else Flow-chart Question within the Tech Board forums, part of the Community Boards category; Hey guys, I am trying to create a flow chart and I am sort of stuck on something that should ...

  1. #1
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72

    If-Else Flow-chart Question

    Hey guys,

    I am trying to create a flow chart and I am sort of stuck on something that should be simple.

    In an If-Else flow, are the diamonds in parallel? I don't think so.

    For example:

    Code:
    if(n < 5){
    
    function1
    function2
    } else if(n < 50){
    function3
    function4
    } else if(n < 500){
    function5
    function6
    }
    I don't know how to express this in a flow-chart. If I express each if statement serially on the chart, then I have to include the follow functions in the flow and that says to my mind that each function is executed.

    However, is each function supposed to be executed if the If-Else statements are phrased like this? If n is less than 5, it is less than 50 and thus less than 500.

    Lets say n = 4. Therefore, the first if statement is true. Does the program jump away from this If-Else structure or does it continue to the next 'else if' statement since that one is true also??

    I'm assuming that it will be caught by the first if statement and then the rest of the 'else if' statements are skipped. If n = 25, then it will fail the first if statement and move to the next 'else if' statement. This is what I do not know how to express in the flow chart!

    Why not just just do a bunch of 'if' statements here? What is the reasoning behind the else ifs?

    I don't know why I am so confused about this, but thanks in advance for the help.

  2. #2
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Well, I think I figured out the flow-chart question:
    Attached Images Attached Images  

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Something like this?
    Code:
          !
          !
          ^
         / \
        /   \
       /     \ Yes
      !  n<5  !--------( function1, function2 )----+
       \     /	                               !
        \   /                                      !
         \ /                                       !
          v                                        !
          ! No                                     !
          !                                        !
          !                                        !
          ^                                        !
         / \                                       !
        /   \                                      !
       /     \ Yes                                 !
      ! n<50  !--------( function3, function4 )----+
       \     /	                               !
        \   /                                      !
         \ /                                       !
          v                                        !
          ! No                                     !
          !                                        !
          !                                        !
          ^                                        !
         / \                                       !
        /   \                                      !
       /     \ Yes                                 !
      ! n<500 !--------( function5, function6 )----+
       \     /                                     !
        \   /                                      !
         \ /                                       !
          v                                        !
          ! No                                     !
          +----------------------------------------+
          !
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    PhysicistTurnedProgrammer Cell's Avatar
    Join Date
    Jan 2009
    Location
    New Jersey
    Posts
    72
    Looks like we ended up with the same idea. I used your format, as it is much neater.

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Flow chart genereting tool
    By Kempelen in forum C Programming
    Replies: 1
    Last Post: 06-04-2009, 08:59 AM
  2. Flow Chart
    By strokebow in forum C++ Programming
    Replies: 2
    Last Post: 11-13-2008, 08:57 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. flow chart
    By SPOOK in forum C Programming
    Replies: 0
    Last Post: 10-08-2001, 03:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21