Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jean y
Java Web Development Techdegree Student 2,074 PointsWhats wrong with this
class Machine {
public static void main (String args[])
throws java.io.IOException {
int i;
for (i = 0; (char) System.in.read() != 'S'; i++)
System.out.println(i);
}
```}
1 Answer
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsYou've made infinite loop. for cycle works like this:
// for ( initial set up; condition to check when looping; what to increment )
for ( i = 0 ; i <= 10; i++ )
In your case (char) System.in.read() != 'S' is not related to i variable anyhow, that's why cycle increments i inifinitely
Checkout in the web more on loops:
http://www.dotnetperls.com/for-java
Or take a nice Workshop with Craig here at Treehouse: