Hi guys, I've been writing programs in awhile, the only think I noticed is that, I rarely using parameters/arguments in my code.
Can anyone briefly explain what is a parameter or a argument?
Java Paramaters, Explains it to me.
Java Paramaters, Explains it to me.
|
Jul 4 2016, 10:44 AM, updated 8y ago
Show posts by this member only | Post
#1
|
Junior Member
206 posts Joined: Jun 2016 From: Planet Earth |
Hi guys, I've been writing programs in awhile, the only think I noticed is that, I rarely using parameters/arguments in my code.
Can anyone briefly explain what is a parameter or a argument? |
|
|
|
Jul 4 2016, 12:35 PM
Show posts by this member only | Post
#2
|
Senior Member
1,206 posts Joined: Dec 2007 From: Kuala Lumpur |
Parameter or arguments is the input to a function.
Just like a program, function can be written to behave different base on the input. Parameter or arguments is the place for one to pass input into the functions. |
|
Jul 12 2016, 09:30 PM
Show posts by this member only | Post
#3
|
Senior Member
3,771 posts Joined: Apr 2010 From: Kota Bharu |
Its kinda late from the date i figure it could help someone in the future. This is a javascript example but should be the same for Java/PHP or whatever, minus some datatype restrictions and annotations.
**my code probably broken, but it should give you the idea CODE //define a function with expected input parameters. function myFunction(parameter1, parameter2) { var a = parameter1; var b = parameter2; var result = a+b; console.log(result); } below is like your main method(in Java) but in javascript doesnt matter lah. suppose you have a return value or arguments, eg: say you have these 2 values, CODE var p1 = 5; var p2 = 2; then call the function, CODE myFunction(p1, p2); //the above function will execute with value 5 and 2 inserted in the parameter1 and parameter2 arguments I used to write redundant codes but after i understood how functions took the arguments, i can just call the same function over and over with only 1 line of code. like, CODE public function 1(p1, p2){ myFunction(p1, p2); } public function 2(p1,p2){ myFunction(p1, p2); } and so on... write once, use how many you want. less lines and cleaner codes. This post has been edited by LuffyPSP: Jul 12 2016, 09:31 PM |
|
Jul 13 2016, 08:30 AM
Show posts by this member only | Post
#4
|
Junior Member
206 posts Joined: Jun 2016 From: Planet Earth |
QUOTE(WongGei @ Jul 4 2016, 12:35 PM) Parameter or arguments is the input to a function. thanks!Just like a program, function can be written to behave different base on the input. Parameter or arguments is the place for one to pass input into the functions. QUOTE(LuffyPSP @ Jul 12 2016, 09:30 PM) Its kinda late from the date i figure it could help someone in the future. This is a javascript example but should be the same for Java/PHP or whatever, minus some datatype restrictions and annotations. wow, thanks! very detail! **my code probably broken, but it should give you the idea CODE //define a function with expected input parameters. function myFunction(parameter1, parameter2) { var a = parameter1; var b = parameter2; var result = a+b; console.log(result); } below is like your main method(in Java) but in javascript doesnt matter lah. suppose you have a return value or arguments, eg: say you have these 2 values, CODE var p1 = 5; var p2 = 2; then call the function, CODE myFunction(p1, p2); //the above function will execute with value 5 and 2 inserted in the parameter1 and parameter2 arguments I used to write redundant codes but after i understood how functions took the arguments, i can just call the same function over and over with only 1 line of code. like, CODE public function 1(p1, p2){ myFunction(p1, p2); } public function 2(p1,p2){ myFunction(p1, p2); } and so on... write once, use how many you want. less lines and cleaner codes. |
|
Jul 18 2016, 11:37 PM
Show posts by this member only | Post
#5
|
Senior Member
661 posts Joined: Dec 2011 |
Thanks , Me also get to refresh !
|
Change to: | 0.0138sec
0.53
5 queries
GZIP Disabled
Time is now: 28th March 2024 - 06:39 PM |