Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!

Ashish Paliwal

Greenhorn
+ Follow
since Oct 07, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ashish Paliwal

So, if I write int i = 10;
then this is a definition not a declaration. Should this work without braces of while loop ?
10 years ago
hmmm probably right.
10 years ago
Ok, probably I figured out the problem.
There is no block scope for that variable. Variables are always declared in some blocks. So that is why it was working with braces.
It happens same way in C also.
10 years ago
Ok, then why does it work after putting braces around while loop.
Also, its not about int i, declare any variable, List l or Object o;

It will give errors.

I am not able to figure put what's the problem
10 years ago
Here is the actual code

10 years ago
I am sorry for undeclared t and capital C. I just wrote rather than copy pasting from IDE.

My point is :

even this

while(true)
int i;

is showing errors. And if I put braces around while loop, everything is working. Say above 2 lines are only thing inside main method. Then also it is not working.
10 years ago
Doesn't matter. Try with length() or with while(true) or with any condition....
it is not working
10 years ago
this is the only code. Only variable declared in whole program is t.

Errors are :

1) '.class" expected
2) not a statement
3) illegal start of expression
4) ; expected

all the errors are in that line only "int t;"

Can someone please try this small program and let me know if this is working. As I told, strangely enough if I put brackets in this one line while loop, it works.
10 years ago
Class A {
public static void main(String args[])
{
String s = "ashish";
t = s.length();
while(t.length > 3)
int i;
}
}

I know this code is not doing anything useful. But my doubt is if I declare any variable inside while loop like this one, then it gives me 4 errors in that line. Doesnt matter which refrence variables you are using int or List.
More strangely, if I put { } in this one statement while loop then it works.
I a absolutely puzzled ??

I am sorry if this sounds too simple for people but I am newbie.
10 years ago