[Gambas-user] Unexecuted Orphan Code or Something?

Bruce bbruen at ...2308...
Tue Nov 5 15:53:38 CET 2013


On Tue, 2013-11-05 at 06:34 -0800, 2aq9j93b7s wrote:
> thank you for the replies I appreciate them
> 
> Unfortunately you are missing the point of the post! I have an uncommeneted
> line of code that is not and cannot be executed
> 
> bruce
> "Now do you see why that last line is not executed."
> My point exactly but when is it executed if at all?
> 
To put it plainly, it will never be executed because it is after the
quite valid Return command.


Private $aChar as String="a"

Private Sub DoNothing()

  Dim bChar As String= "b"

  Return

  $aChar=bCar

' plus a whole bunch of further code that will
' never  be executed because this Sub has 
' already Returned, like
  Format(Now(),"yy-mm-dd")
  Now()
' etc  


End


Public Sub Main()

  DoNothing

  Print $aChar

End


What you appear to have fallen for is the old
putting a comment in the middle of a multiline
command. As soon as you do that you have terminated the
command and the "lines of code" after that are never executed
because you have already got a valid Return command.

Secondly, don't forget that all Gambas functions can be 
used as subs. So, the things that look like dangling functions
in the code above aren't. They are functions used as subs.

Bruce








More information about the User mailing list