magicyte
11-03-2008, 02:43 AM
The Incomplete "return" Tutorial
Author: Mr. W. / magicyte
This tutorial's code examples are based completely on JavaScript and may not work in other coding languages.
Prologue: "Why?"
----This "tutorial" (per se) will inform even the most "impaired" programmers (programmers that don't understand) what the 'return' keyword does and kinda how it works. This tutorial was created by a programmer. Programmers are humans, and humans make mistakes. In the Epilogue, reporting of errors, suggestions, and comments will be asked for. In other words, this 'tutorial' definately has mistakes. This 'tutorial' is based on general 'return' situations wherein a function is called and it then returns a value, in any case an integer (of any type), character, or string. Some may be thinking "Well, EVERYONE gets the 'return' keyword". This 'tutorial' is, once again, made for people who don't quite understand the 'return' keyword: what it does, or even how it works. Alas, the 'tutorial' begins:
Chapter 1: "What?"
----What is 'return'? Well, it is a keyword that may be found in a function (most often, actually). This keyword will take the variable/inline character, string, or integer and return it, or send it back to the main function (on websites, back to the application's main runtime function [your internet browser]/on applications, back to the main() function). Also, once the return keyword is called, it returns the value, but it also exits the function and goes back to regular runtime execution/the main function. Examples:
// inline return values
function getFive () {
return 5; // returns integer 5 - will also exit function and go back to main function
}
function getHi_There () {
return "Hi_There"; // returns string "Hi_There" - will also exit function and go back to main function
}
// variable return values
function getFive () {
var num = 5;
return num; // returns 5 from variable num - will also exit function and go back to main function
}
function getHi_There () {
var str = "Hi_There";
return str; // returns "Hi_There" from variable str - will also exit function and go back to main function
}
It is also possible that you return functions that return things, as well:
function rt () { // will return "HI!!" - will also exit function and go back to main function
return "HI!!";
}
function rthi () { // will return rt()'s return value - "HI!!" - will also exit function and go back to main function
return rt();
}
You can also manipulate values in functions (I'm sure you could figure out how and why). And since everything in programming is numbers, you can return practically ANYTHING! Amazing!
Chapter 2: "How?"
----Now, I see return values as inline pieces of code found in main functions. This is because you can return a function that just runs code! This will place it in the main function! Not exactly, but I think you know what I mean. This is how I think it works.
An example. When you return an alert, it will alert something. You can try it by calling this function:
function rtatvl () {
return alert("whatever you want here.");
}
I hope you understand what I am trying to say. I see return values being placed in to the main function in programs. All right, so when I see this in a function and the function is called:
function rtwtiwnt () {
return alert("anything");
}
... I think of this being in regular code:
alert("anything");
Try this:
function rtwtvt () {
return 111;
}
function rtalrtwtvt () {
return alert("I am " + rtwtvt() + " years old.");
}
When rtalrtwtvt() is executed, I see code like this:
alert("I am 111 years old.");
Please ask for clarification if this is vivid (I think it is, otherwise I wouldn't have said so). Since some members may not be Senior Coders who don't just get it, you may Private Message (PM) me by using the link in my signature at the end.
Epilogue: "Help!"
----This tutorial is in need of a makeover! Post any errors, suggestions, and comments you may have that will help in the progress of this 'tutorial'.
Projects 4 You:
----Here is/are some special project(s) that you can try out.
1. Find the output of rtspecialrt()
function atip () {
return "Hello.";
}
function btip () {
return " My name i";
}
function ctip () {
return "s Art.";
}
function rtspecialrt () {
return atip() + btip() + ctip();
}
Link(s) I Didn't Use That Might Be Helpful:
----Here are/is some/a link(s) that I didn't use that might be helpful to use. In fact, I didn't use any resources except my brain:
- The Return Keyword (http://jennifermadden.com/javascript/returnKeyword.html)
- return Keyword for Form Validation (http://jennifermadden.com/javascript/formReturn.html)
THE END
Author: Mr. W. / magicyte
This tutorial's code examples are based completely on JavaScript and may not work in other coding languages.
Prologue: "Why?"
----This "tutorial" (per se) will inform even the most "impaired" programmers (programmers that don't understand) what the 'return' keyword does and kinda how it works. This tutorial was created by a programmer. Programmers are humans, and humans make mistakes. In the Epilogue, reporting of errors, suggestions, and comments will be asked for. In other words, this 'tutorial' definately has mistakes. This 'tutorial' is based on general 'return' situations wherein a function is called and it then returns a value, in any case an integer (of any type), character, or string. Some may be thinking "Well, EVERYONE gets the 'return' keyword". This 'tutorial' is, once again, made for people who don't quite understand the 'return' keyword: what it does, or even how it works. Alas, the 'tutorial' begins:
Chapter 1: "What?"
----What is 'return'? Well, it is a keyword that may be found in a function (most often, actually). This keyword will take the variable/inline character, string, or integer and return it, or send it back to the main function (on websites, back to the application's main runtime function [your internet browser]/on applications, back to the main() function). Also, once the return keyword is called, it returns the value, but it also exits the function and goes back to regular runtime execution/the main function. Examples:
// inline return values
function getFive () {
return 5; // returns integer 5 - will also exit function and go back to main function
}
function getHi_There () {
return "Hi_There"; // returns string "Hi_There" - will also exit function and go back to main function
}
// variable return values
function getFive () {
var num = 5;
return num; // returns 5 from variable num - will also exit function and go back to main function
}
function getHi_There () {
var str = "Hi_There";
return str; // returns "Hi_There" from variable str - will also exit function and go back to main function
}
It is also possible that you return functions that return things, as well:
function rt () { // will return "HI!!" - will also exit function and go back to main function
return "HI!!";
}
function rthi () { // will return rt()'s return value - "HI!!" - will also exit function and go back to main function
return rt();
}
You can also manipulate values in functions (I'm sure you could figure out how and why). And since everything in programming is numbers, you can return practically ANYTHING! Amazing!
Chapter 2: "How?"
----Now, I see return values as inline pieces of code found in main functions. This is because you can return a function that just runs code! This will place it in the main function! Not exactly, but I think you know what I mean. This is how I think it works.
An example. When you return an alert, it will alert something. You can try it by calling this function:
function rtatvl () {
return alert("whatever you want here.");
}
I hope you understand what I am trying to say. I see return values being placed in to the main function in programs. All right, so when I see this in a function and the function is called:
function rtwtiwnt () {
return alert("anything");
}
... I think of this being in regular code:
alert("anything");
Try this:
function rtwtvt () {
return 111;
}
function rtalrtwtvt () {
return alert("I am " + rtwtvt() + " years old.");
}
When rtalrtwtvt() is executed, I see code like this:
alert("I am 111 years old.");
Please ask for clarification if this is vivid (I think it is, otherwise I wouldn't have said so). Since some members may not be Senior Coders who don't just get it, you may Private Message (PM) me by using the link in my signature at the end.
Epilogue: "Help!"
----This tutorial is in need of a makeover! Post any errors, suggestions, and comments you may have that will help in the progress of this 'tutorial'.
Projects 4 You:
----Here is/are some special project(s) that you can try out.
1. Find the output of rtspecialrt()
function atip () {
return "Hello.";
}
function btip () {
return " My name i";
}
function ctip () {
return "s Art.";
}
function rtspecialrt () {
return atip() + btip() + ctip();
}
Link(s) I Didn't Use That Might Be Helpful:
----Here are/is some/a link(s) that I didn't use that might be helpful to use. In fact, I didn't use any resources except my brain:
- The Return Keyword (http://jennifermadden.com/javascript/returnKeyword.html)
- return Keyword for Form Validation (http://jennifermadden.com/javascript/formReturn.html)
THE END