system
August 12, 2010, 6:00am
1
I want to make a function(or whatever) that returns a value. By that I mean I want to be able to do something like:
if(function == value) { //or would it be "function() == value"??
do something
}
I know I could just set a variable equal to something in said function, but I think this would be cleaner...
The way I would intend to make this function would be with the following syntax:
function void() {
value returned by function generated here...
}
Is this possible somehow? I have no formal training with programming, but I am starting to get better. Any help would be greatly appreciated.
Thanks.
pat
system
August 12, 2010, 6:28am
2
Just use the return statement:
int function() {
return 12;
}
system
August 12, 2010, 7:51am
3
Thanks drhex. I ended up using "boolean function()..." instead. That way my if statements are more literal. if( somethingHappened() )... do this..
system
August 12, 2010, 9:08am
4
I ended up using "boolean function()..."
Bit of C/C++ background:
In C, any non-zero value (positive or negative) is regarded as "true", and only zero is regarded as "false".
Thus, in DrHex's example, "if (function())" would always evaluate as "true", because 12 is non-zero.
system
August 14, 2010, 11:08pm
5
Sorry for replying so late. I understand what you are saying AWOL. My function, though, was a little more involved than drhex's example. The statements in my function return either a true or a false depending on the conditions. I know I could use int and return either a 1 or a 0. I guess boolean seems more professional? More like the way it should be.. Thanks for the advice.
pat