Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsUnable to produce a simple while loop outcome.
https://www.eclipse.org/forums/index.php/mv/msg/839786/1454796/#msg_1454796
public class Application {
public static void main(String[] args) {
int value = 0;
while(value < 10);
{
System.out.println("Hello" + value);
value = value + 1;
}
}
}
]]>michael mccarty2014-10-28T19:40:23-00:00Re: Unable to produce a simple while loop outcome.
https://www.eclipse.org/forums/index.php/mv/msg/839786/1454862/#msg_1454862
I think if you replace
Quote:
while(value<10);
with
Quote:
while(value<10) // no semicolon
you will be ok.
Jim A.]]>Jim Anderson2014-10-28T21:14:53-00:00Re: Unable to produce a simple while loop outcome.
https://www.eclipse.org/forums/index.php/mv/msg/839786/1454889/#msg_1454889
michael mccarty2014-10-28T21:53:58-00:00Re: Unable to produce a simple while loop outcome.
https://www.eclipse.org/forums/index.php/mv/msg/839786/1455045/#msg_1455045
Hi Michael,
You just have to get used to the java syntax more (and it's short cuts).
I'm not a language guru, so my explanation here is not really too formal.
Anyway, the syntax for a while loop, is something like:
while ( condition ) code_block
where 'code_block' is executed if 'condition' is true.
Normally, a block of code is delimited by { }. But block can be simply a single statement,
so a while loop could be:
while ( condition ) System.out.println("Hi");
Note, the lack of brackets.
Now, if the single statement of the while loop is a null statement, it could look like
while ( condition ) ;
which will do nothing as long as condition is true. If the condition is true, it will always be true once the loop is entered.