Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860
Bargains With Evil - Huben's Wiki

Bargains With Evil

From Huben's Wiki
Jump to: navigation, search
(Lawyer Up To Read Other Contracts)
(Read The Contract Carefully!)
Line 42: Line 42:
 
The first thing we must understand in these code examples is the idea of '''local variables'''.  Local variables are declared within methods, while the variables we have seen up until now are declared outside of methods.  Local variables can ONLY be used inside their own methods, and actually only within their own block and any inner blocks.  This is a principle called '''scope'''.  Arguments in method signatures are also local variables.
 
The first thing we must understand in these code examples is the idea of '''local variables'''.  Local variables are declared within methods, while the variables we have seen up until now are declared outside of methods.  Local variables can ONLY be used inside their own methods, and actually only within their own block and any inner blocks.  This is a principle called '''scope'''.  Arguments in method signatures are also local variables.
  
A method call sets argument variables in the method.  In the Innocent.main() call to Evil.bargain(), Evil.bargain()'s whatIsGiven argument is set to the String "honor".  Methods can return a single value, which can be placed in a variable, used, or ignored.  Evil.bargain() returns a string with the value "despair" to Innocent.main(), which places that value into the String named 'result'.
+
A method call sets argument variables in the method.  In the Innocent.main() call to Evil.bargain(), Evil.bargain()'s whatIsGiven argument is set to the String "honor".   
 +
 
 +
Methods can return a single value, which can be placed in a variable, used, or ignored.  A method returns a value using the '''return''' reserved word, as you see at the end of both methods of Evil.  If the return type of a method is '''void''', no value is returned and there is no need for a return statement.  Evil.bargain() returns a string with the value "despair" to Innocent.main(), which places that value into the String named 'result'.
  
 
Arguments and returns can be any types or combination of types.
 
Arguments and returns can be any types or combination of types.

Revision as of 15:11, 25 September 2012

Personal tools
translate