Declaring variables for limited scope at the head of the for loop

Posted by Helper Method on Stack Overflow See other posts from Stack Overflow or by Helper Method
Published on 2010-04-14T12:26:09Z Indexed on 2010/04/16 22:23 UTC
Read the original article Hit count: 154

Filed under:

In Java, you sometimes do something like this:

for (int a = 1, b = 2; b < high;) {
    if (b % 2 == 0) {
        result += b;
    }

    int tmp = b;
    b       = a + b;
    a       = tmp;
}

Here, I used a for loop instead of a while loop to limit the scope of a and b.

But how can I achieve this in JavaFX? The for loop doesn't seem to offer this possibility. Do I have to use a while loop?

© Stack Overflow or respective owner

Related posts about javafx