Page 48 -
P. 48

starting to code


           Codeville: Your program is like a network

           of roads

           Programs need to do different things under different circumstances. In
           the game, the code displays “You win!” if the user guesses the number
           correctly, and “You lose!” if not. This means that all programs, even really
           simple programs, typically have multiple paths through them.

















                                                                              There are decision points in
                                                                              every program that are like
                                                                              road intersections.



                                                                                        The computer runs the
                                                                                        commands that it finds
                                                                                        on the “path" it takes
                                                                                        through the code.




              There are many roads (or
               paths) through the code.


          A path refers to the set of instructions that the computer will actually
           follow (or execute). Your code is like a street network, with lots of sections
           of code connected together just like the streets in a city. When you drive
           through a city, you make decisions as to which streets you drive down by
           turning left or right at different intersections. It’s the same for a program.
           It also needs to make decisions from time to time as to which path to take,
           but for your code, it is not like driving along a road, it’s executing a particular
           path.
           Let’s look in more detail at how a program decides
           which path to take.

                                                                                        you are here 4    13
   43   44   45   46   47   48   49   50   51   52   53