Am Mittwoch, den 02.05.2007, 17:28 +0200 schrieb Bernd Eilers:
> Code like this would do behave just like that in java.
Are you really sure? If so, please verify ... see below.
> The assumptions about java programming shown here are just plain wrong.
> In fact I pretty much doubt that there is any programming language out
> there where setting a variable means to exit the function.
If you view it that way, it is.
But in Java the result of a function is set by using return (assigning a
value to the function name is an error, as long as there is no variable
with the same name), and "return" has the same task as a variable named
like the function in BASIC: transporting the result to the caller.
But in Java - and C++ as I learned now - the return statement *does*
exit the function.
Marc
class FunctionDemo {
boolean getBool(int v) {
if (v == 1) {
return true;
}
return false;
}
void run() {
boolean b = getBool(0);
System.out.println(b);
b = getBool(1);
System.out.println(b);
}
public static void main( String[] args ) {
FunctionDemo me = new FunctionDemo();
me.run();
}
}
Gives the following output:
$ javac FunctionDemo.java
$ java FunctionDemo
false
true
$
qed
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]