Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

byte

 
Vishal Arora
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The output of this code given below is "Welcome to Java".Can somebody tell me why it is not an infinite loop printing welcome to java.
public class XTC {

public static void main ( String [ ] args ) { // ---> line 1
XTC x = new XTC();
x.infiniteLoop();
}
void infiniteLoop ( ) {
byte b = 1 ;
while ( ++b > 0 ) ;
System . out . println ( " Welcome to Java " ) ;
}

}
 
satya mamillapalli
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Watch the end of WHile loop? It ends with semicolon.(it is an empty loop)

Actaully empty loop will execute 126 times and comes out because after 127 it will start with -128..

Thanks

Satya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic