嗔秤戻幣�哉膵�云利匈嬉蝕湊蛸賜�塋床四衲���萩晦編報炎嘔囚^泡仟 ̄云利匈�《超噌�殻窟�嵌虜隆輓麈觚翹瀘卉韮�仍仍�。� 烏御危列
浪慕利 卦指云慕朕村 厘議慕尺 厘議慕禰 TXT畠云和墮 序秘慕杏 紗秘慕禰

VB2008貫秘壇欺娼宥(PDF鯉塀哂猟井)-及41嫗

梓囚徒貧圭�鮗� ○ 賜 ★ 辛酔堀貧和鍬匈��梓囚徒貧議 Enter 囚辛指欺云慕朕村匈��梓囚徒貧圭�鮗� ● 辛指欺云匈競何��
!!!!隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��






                  Loop used to generate the index                        Function that determines whether or not the search can 

                  series for the Connections array                            continue to the next Connections array element 



             Private Function FindNextLeg��ByVal returnArray As Node�┌��察�_ 

                                          ByVal count As Integer�察�_ 

                                          ByVal destination As String�察�_ 

                                          ByVal currNode As Node�� As Boolean 



                 For c1 As Integer = 0 To currNode。Connections。Length 1 

                     If CanContinueSearch��returnArray�察�currNode。Connections��c1���� Then                   Assume that you can go to the 

                         returnArray��count�� = currNode。Connections��c1��                                   connection�察�so add it to the 

                         If currNode。Connections��c1��。CityName。pareTo��destination�� = 0 Then 

                             Return True                                                                      found route array 

                         Else 

                             If FindNextLeg��returnArray�察�count �� 1�察�destination�察�_ 

                                            currNode。Connections��c1���� Then                   If the current connection is the 

                                 Return True 

                             End If                                                          end�察�stop searching down the 

                         End If                                                                      tree and return 

                     End If                  Current connection is not the end�察�so go to 

                 Next                         the connection and find another flight leg 

                 Return False 

             End Function                       that will bring you to the destination 



            Figure 4´16。 FindNextLeg�┌� looks for the next leg in the journey。 



                  The big idea here is to create a flight route by traveling the tree of connections in the hope  

            that one of the connections will cause you to end up at your end point。 Notice that for each leg�察 �

            the parameter count is incremented�察�so as you progress a level deeper in the tree�察�you assign  

            the city at the level to the found route array。 

                  What makes this function tick is the decision code represented by an  If code block。 The If  

            code block says�察 �If this decision test is true�察�then execute the code within the If block�察�other

            wise�察�move to the code immediately after the  If block。 ̄  

                  An  If statement has the following form�此�



            If ��condition�А�Then 

               ��Do action�А�

            ElseIf ��condition�А�Then 

                ��Do action�А�

            Else  

                ��Do action�А�

            End If 



                  The statements  If�察�ElseIf�察�and Else together represent one piece of logic ��for example�察�if  

            this cannot happen�察�then test the ElseIf�察�if that cannot happen�察�then do the default in the Else��。  

            The statements after the first  If are optional。 

                  The  ��condition�А�must return a True or False value。 A True value means to execute the actions  

            within the block�察�and a  False value means to try the next code statement。 

                  The Else statement is a sort of default catchall that is executed if none of the other  If state

            ments prove to be true。 

                  Here is an example of logic executed in an If statement�此�



            If test1 Then 

              ' Code1 

            ElseIf test2 Then 

              ' Code2 


´´´´´´´´´´´´´´´´´´´´´´Page 129´´´´´´´´´´´´´´´´´´´´´´´

                       CH AP T E R   4   *    L E A R N I N G   A B OU T   D AT A  S TR U CT U R E S�察  �DE CI SI ON S�察  �A N D   L O OP S 107 



Else  

  ' Code3 

End If 

' Code4 



     The following code steps are executed�此�



     o  If test1 is True�察�then execute Code1。 After executing Code1�察�execute Code4。 



     o  If test1 is  False�察�jump to ElseIf with test2。 



     o  If test2 is True�察�then execute Code2。 After executing Code2�察�execute Code4。 



     o  If test2 is  False�察�jump to Else。 



     o  Execute Code3。 After executing Code3�察�execute Code4。 



     Here is another example�此�



If test1 Then 

  ' Code1 

Else  

  ' Code2 

End If 

 ' Code3 



     The executed code steps are as follows�此�



     o  If test1 is True�察�then execute Code1。 After executing Code1�察�execute Code3。 



     o  If test1 is  False�察�jump to Else。 



     o  Execute Code2。 After executing Code2�察�execute Code3。 



     And here is one more example�此�



If test1 Then 

  ' Code1 

End If 

If test2 Then 

  ' Code2 

Else  

  ' Code3 

End If 

// Code4 



     The executed code steps are as follows�此�



     o  If test1 is True�察�then execute Code1。 After executing Code1�察�jump to If with test2。 



     o  If test1 is  False�察�jump to If with test2。 



     o  If test2 is True�察�then execute Code2。 After executing Code2�察�execute Code4。 


´´´´´´´´´´´´´´´´´´´´´´Page 130´´´´´´´´´´´´´´´´´´´´´´´

108       CH AP T E R   4   *    L E A R N IN G   AB OU T   D AT A  S TR U CT U R E S�察  �DE CI SI ON S�察  �A N D   L O OP S 



               o  If test2 is  False�察�jump to Else。 



               o  Execute Code3。 After executing Code3�察�execute Code4。 



                The following code is illegal�此�



           Else  

             ' Code2 

           End If 

           ' Code3 



                And this is also illegal�此�



           ElseIf test2 Then 

             ' Code2 

           Else  

             ' Code3 

           End If 



                It is possible to have one If statement embedded within an  Else�察�If�察�or ElseIf to create a  

           more plex multilevel decision tree。 

                The condition or test��N �А�variables are Boolean values that can contain True or  False。 You  

           have already seen examples of these�察�like this�此�



           If CanContinueSearch��returnArray�察�currNode。Connections��c1���� Then 



                The If statement says that if the method CanContinueSearch�┌� returns True�察�then execute  

           the contained code。 

                Here is another example of a condition�此�



           If returnArray��c1�� IsNot Nothing  Then 



                This If statement says that if the array element returnArray��c1�� does not have a value of  

           Nothing�察�then execute the contained code。 

                In both examples�察�either the method or parison must return a Boolean value。 If a Boolean  

           value is not returned�察�the Visual Basic piler will generate an error indicating that the code  

           does not result in a True or  False value。 

                It is easy to see how a method can generate a True or False value�察�but the array element not  

           equal to Nothing statement is a bit more plicated。 The statement is an example of using  

           operators to perform a parison。 parisons test if things are equal to each other or not  

           equal to each other。 Table 4´2 shows the parison operators and what they mean。  



           Table 4´2。  parison Operators 



           Expression          Description 



           a = b               Does a equal  b�拭�



           a  b              Does a not equal  b�拭�



           a 〃 b               Is a greater than b�拭�



           a ゞ b               Is a less than  b�拭�


´´´´´´´´´´´´´´´´´´´´´´Page 131´´´´´´´´´´´´´´´´´´´´´´´

                        CH AP T E R   4   *    L E A R N I N G   A B OU T   D AT A  S TR U CT U R E S�察  �DE CI SI ON S�察  �A N D   L O OP S 109 



Table 4´2。  parison Operat
卦指朕村 貧匯匈 和匯匈 指欺競何 壘��0�� 家��0��
隆堋響頼��紗秘慕禰厮宴和肝写偬堋響��
梁椣戻幣�� 梁心弌傍議揖扮窟燕得胎��傍竃徭失議心隈才凪万弌誌育断蛍�輌臆惨軼僑〃�燕慕得珊辛參資誼持蛍才将刮襲潜��範寔亟圻幹慕得 瓜寡追葎娼得辛參資誼寄楚署衛、持蛍才将刮襲潜填��