Hi guys just wanted some clarification on two issues.

Nested Loops, I just want to clarify how i should read these for example:

public void nestedForLoop()
   {
       int i = 0;
       int j = 0;
       
     for (i = 0; i < 10; i++)
       {
         for (j = 0; j < 3; j++)
         {
             System.out.println("Inside both loops: " + i +"\t"+ j);
         }
       System.out.println("Inside outer loop: " + i +"\t"+ j);
      }
      System.out.println("Outside Loop: " + i +"\t"+ j);
   }

How should i read a nested for loop? Like would this run essentially 30 times? Does it basically say run the inside loop 10 times? So then does it basically run once, go into the nested loop, run 3 times, then go back into the outer loop, then back into the nested loop 3 times?

And I'v read a few definitions and my lecturer has failed what a 'literal' is effectivley. So can i ask, what are they?

Thanks in advance, just want to clear the ideas in my head, because they're surrounded by a lot of confusion.

How should i read a nested for loop? Like would this run essentially 30 times? Does it basically say run the inside loop 10 times? So then does it basically run once, go into the nested loop, run 3 times, then go back into the outer loop, then back into the nested loop 3 times?

Yes, the inner code will be run 30 times. Basically, the outer loop is run 10 times, and each time the outer loop is run the inner loop is run 3 times, (plus the output line is run once each time the outer loop is run).

And I'v read a few definitions and my lecturer has failed what a 'literal' is effectivley. So can i ask, what are they?

A literal is not a terminology I am immediately familiar with, what is the context?

Well i haven't really got an example but maybe you can explain this definition i found to me because i'm not sure what it means:

A literal represents a value of a certain type where the type describes how that value behaves.

There are different types of literals namely number literals, character literals, boolean literals, string literals,etc.

This link has a good explanation of primitives and literals. Let us know if you still have questions after reading this page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.