Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please exaplin this code

 
Akhilesh Yadav
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Char
{
public static void main(String arg[])
{
while(false) //1
{
System.out.println("Hello");
}
while(false) //2
{
}
do;
while(false);
do
{
;
}
while(false);
}
}

when i run this programm it gives me error at first while //1 saying unreachable code becuase while is false
i chnaged it to true first while its working

same erroer for second while but when i changed second while to true its still showing unreachable code please can anyone Expalin me why ?
 
Anton Uwe
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take a look at a simplier code example:

If you have "false" in //1, the code inside the braces (printing "Hello1") is unreachable. If you have "true" in //1, the code after the braces (printing "Hello2") is unreachable.
 
Giri Kanduri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Char{
public static void main(String arg[]){
while(true) //1
{
System.out.println("Hello");
}
while(true) //2
{
}
}
}

In the above code it will not reach the second while loop bcz the first while loop is an infinite loop...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic