Link to home
Create AccountLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

Loop program

package com.vaannila.student;

public class MyLoop{
      public static void main(String argv[]){
      MyLoop ml = new MyLoop();
      ml.amethod();
      }

       public void amethod(){
                for(int K=0;K<5l;K++){
                     System.out.println("Outer "+K);
                     for(int L=0;L<5;L++)
                     {System.out.println("Inner "+L);}
                   }
          }
}

I was trying above example from link
http://www.jchq.net/certkey/0202certkey.htm
got output like



Outer 0
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Outer 1
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Outer 2
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Outer 3
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Outer 4
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4


I was trying to understand the output.Why outer loop did not execute until 50 times( ask<51). Please advise. Any links, ideas, resources,sample code highly appreciated. thanks in advance.
Avatar of for_yan
for_yan
Flag of United States of America image

That is not digit "1" but letter "l" which yu hvae in "51"  
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
By the way if you want it to execute 50 times you should have it

K<50 (not K<51) as it starts with 0

 
Avatar of gudii9

ASKER

>>>That is not digit "1" but letter "l"

what is use of that character in this for loop. please advise
SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.