Hi all,
I am new to Java and basically have a question regarding the for loop.
The following code;
int poweroftwo;
int x;
for (int n = 1; Math.pow(2,n) < 100; n++)
{
poweroftwo = (int)Math.pow(2,n);
}
//Execute after for loop
System.out.println(poweroftwo);
However i get an error, Variable poweroftwo is not define, but when i use a while loop instead everything is fine.
Is there a difference?
Thanks in advance.
Yue Jeen
[sig][/sig]
I am new to Java and basically have a question regarding the for loop.
The following code;
int poweroftwo;
int x;
for (int n = 1; Math.pow(2,n) < 100; n++)
{
poweroftwo = (int)Math.pow(2,n);
}
//Execute after for loop
System.out.println(poweroftwo);
However i get an error, Variable poweroftwo is not define, but when i use a while loop instead everything is fine.
Is there a difference?
Thanks in advance.
Yue Jeen
[sig][/sig]