Hot Posts

Unusual for and if-then-else constructions that ARE NOT valid.

Unusual loop/conditional constructions that ARE NOT valid.

       for (int x = 0; x<5; x++)
            System.out.println(x);
      System.out.println(x); // out of scope error
for (int x = 0; x<5; x++)
       for (int y = 0; y<5; y++)
             for (int z = 0; z<5; z++)

There must be a line of code that is executed after the last for statment.

       for (int x = 0; x<5; x++)
             for (int y = 0; y<5; y++)
                   for (int z = 0; z<5; z++)
                        System.out.println(z);
            System.out.println(y); // out of scope
      System.out.println(x); // out of scope
       for (int i = 0; i < 3; i++)
            System.out.println("i = " +i);
             for (int j = 0; j < 3; j++)
                  System.out.println("j = " + j);
                  System.out.println("j = " + j); // out of scope
                   for (int k = 0; k < 3; k++)
                        
                        System.out.println("k = " + k);
            System.out.println(k);   // out of scope

In nested loops without braces there must be one line of code and optionally a for statement. If there are two or more lines of code then we have compile time problems.

     if (true) { break ; }

Cannot have break or continue in an ‘if’ or ‘else’ block.

     if();
     if (true ) else; // Else is not a valid statement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: