Original Post
Working through java, a beginners guide 5th ed one of the examples:
[source lang="java"]public class forDemo {
// Demonstrates the for loop
public static void main(String[] args) {
// TODO Auto-generated method stub
int count;
for (count = 0; count < 5; count = count + 1);
System.out.println( "This is count: " + count);
System.out.println( "Done!");
}
}[/source]
The author goes on to say that the example is not good programming and that you will not see programmers use that example, you would probably se this instead: count++.
But when I run it with the latter:
[source lang="java"]
public class forDemo {
// Demonstrates the for loop
public static void main(String[] args) {
// TODO Auto-generated method stub
int count;
for (count = 0; count < 5; count = count++);
System.out.println( "This is count: " + count);
System.out.println( "Done!");
}
}
[/source]
it runs "this is count: 0 infinitely
thanks for any help.
[source lang="java"]public class forDemo {
// Demonstrates the for loop
public static void main(String[] args) {
// TODO Auto-generated method stub
int count;
for (count = 0; count < 5; count = count + 1);
System.out.println( "This is count: " + count);
System.out.println( "Done!");
}
}[/source]
The author goes on to say that the example is not good programming and that you will not see programmers use that example, you would probably se this instead: count++.
But when I run it with the latter:
[source lang="java"]
public class forDemo {
// Demonstrates the for loop
public static void main(String[] args) {
// TODO Auto-generated method stub
int count;
for (count = 0; count < 5; count = count++);
System.out.println( "This is count: " + count);
System.out.println( "Done!");
}
}
[/source]
it runs "this is count: 0 infinitely
thanks for any help.