Unable to produce a simple while loop outcome. [message #1454796] |
Tue, 28 October 2014 19:40 |
michael mccarty Messages: 2 Registered: October 2014 |
Junior Member |
|
|
My eclipse has ran every program ive made so far except one simple while loop. It doesn't give me any error messages and it looks as if its about to run the program but it just doesn't. Almost like its lagging but to test this I clicked run and went to sleep and woke up with still no result. Has anyone else had this issue? Here is a sample of my simple while loop just in case im doing something wrong with it:
public class Application {
public static void main(String[] args) {
int value = 0;
while(value < 10);
{
System.out.println("Hello" + value);
value = value + 1;
}
}
}
[Updated on: Tue, 28 October 2014 20:44] by Moderator Report message to a moderator
|
|
|
|
|
Re: Unable to produce a simple while loop outcome. [message #1455045 is a reply to message #1454889] |
Wed, 29 October 2014 01:52 |
Jim Anderson Messages: 109 Registered: October 2014 |
Senior Member |
|
|
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.
The above while loop can also be written as:
while ( condition )
{
;
}
I hope this helps you.
Jim
|
|
|
Powered by
FUDForum. Page generated in 0.03818 seconds