Does the Position of the 'return' Operator Matter in Relation to Closing Braces?

To add comments, please log in or register
koranged
367
koranged  

Still reading through the tutorial/manual, on the later stages now and have come across an example which has left me a bit confused.

'return' is of course used to terminate the current function... in this example, the special start() function is the only function used, but if 'return' terminates this function, then what is the need for the closing braces which succeed it? I know that a closing brace usually follows the 'return' operator but I thought that this was the closing brace of the function... in this example, 'return' is used prior to the closing braces of the external while(true) cycle and the OnStart() function (according to the program notes (//)).

      Alert ("The script has finished operations --------------------------");
         return;                                // Exit start()
        }					// 
     }                                          // Closing Brace of while(true)
//----------------------------------------------------------------------
  }   						// Closing Brace of OnStart()
//----------------------------------------------------------------------

Is there any difference between the above and below examples in terms of program execution? Is it acceptable to use the below code rather than the above to end the script?

       Alert ("The script has finished operations --------------------------");
        }                                       // Closing Brace of while(true)
     }                                          // Closing Brace of OnStart()
//-------------------------------------------------------------- 10 --
   return;                                
  }   
//--------------------------------------------------------------------
Keith Watford
Moderator
13969
Keith Watford  

 but if 'return' terminates this function, then what is the need for the closing braces which succeed it?

The first return may be conditional on a block of code.

You may want to add additional code later for when the condition is not satisfied.

Your example may be a poor example as there is no more code after the Alert.

To add comments, please log in or register