We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Very new and need a little help please
Page Index Toggle Pages: 1
Very new and need a little help please (Read 337 times)
Very new and need a little help please
Dec 8th, 2008, 2:52pm
 
I am quite new and seem to be getting the same problem, which is "unexpected token: )"
I want to read from a text file the amount of lines, then return a string if there are more than a certain number of lines and return a different string if there are less then that number of lines.
The code I am using is:

String lines[] = loadStrings("test.txt");
int i = lines.length;
for (i >= 3;) {
 println("More than 3");
}
for (i < 3;) {  
   println("Less than 3");  
}
Re: Very new and need a little help please
Reply #1 - Dec 8th, 2008, 2:55pm
 
try

if(i >= 3) {
 ...
}

'for' is for loops, 'if' for conditions
Re: Very new and need a little help please
Reply #2 - Dec 8th, 2008, 3:02pm
 
No luck, now get the following error:
"Syntax error, maybe a missing right parenthesis?"
Re: Very new and need a little help please
Reply #3 - Dec 8th, 2008, 3:03pm
 
sorry, my fault, needed to take out the ";" if using "if"
Thanks.
Re: Very new and need a little help please
Reply #4 - Dec 8th, 2008, 8:56pm
 
another tip: try using else instead of another if statement:

Code:

if (i >= 3) {
//do something
}
else {
//do something else
}


this code is easier to understand and easier to manage if the conditional changes. you would only have to change it in one place.
Page Index Toggle Pages: 1