Android Question Nested loop

Discussion in 'Android Questions' started by Sub7, Feb 14, 2015.

  1. Sub7

    Sub7 Active Member Licensed User

    Sorry for the dumb question, i know is something elementary but i'm stuck.

    Code:
    Dim maxn As Int = 5
    For i = 0 To  5
    i = i+
    1

        
    For k = 0 To maxn
        
    Log(k)
        
    Next

    Next
    The output is
    -0 1 2 3 4 5
    - 0 1 2 3 4 5
    - 0 1 2 3 4 5

    While i want the inner loop to generate:

    - 0 1 2 3 4
    - 5 6 7 8 9
    - 10 11 12 13 14 and so on.

    Thanks :p
     
  2. sorex

    sorex Expert Licensed User

    Code:
    Dim maxn As Int = 5
    For i = 0 To  5
    'i = i+1   remove this

        
    For k = 0 To maxn
        
    Log(i*5+k)
        
    Next

    Next
     
    Last edited: Feb 14, 2015
  3. Sub7

    Sub7 Active Member Licensed User

    Hi Sorex :) look this

    5
    6
    7
    8
    9
    10

    15
    16
    17..


    While i want the inner loop to generate:

    - 0 1 2 3 4
    - 5 6 7 8 9
    - 10 11 12 13 14

    Thx :p
     
  4. sorex

    sorex Expert Licensed User

    that's because you have an unneeded i=i+1 there

    you also might need for k=0 to ...-1 depending on how you definded that variable (taking into account that it start from 0 or 1)
     
  5. Sub7

    Sub7 Active Member Licensed User

    yeah right, thank you friend.
     
  6. Sub7

    Sub7 Active Member Licensed User

    Code:
    Dim maxn As Int = 5
    For i = 0 To  5
      
    For k = 0 To maxn -1
      
    Log(i*5+k)
      
    Next
       
    Log("five blocks")
    Next
     
  7. Sub7

    Sub7 Active Member Licensed User

    hmmm it's more tricky that what i tought, this is what i wanted to do:
    I have to load 50 different images, to make this works i think i need five inner loops-

    Code:
    Dim maxn As Int = 5
    For i = 0 To  5

         
    Dim p As Panel
         p.Initialize(
    "")
         p.color = 
    Colors.ARGB(255,235,235,235)
         clv.Add(p, 
    71dip"test")
         p.LoadLayout(
    "clv_layout")


      
    For k = 0 To maxn -1
           
    Dim g As Int = i*5+k
           img_ornnament1.Bitmap = 
    LoadBitmapSample(File.DirAssets, "img_s/"& g&"_image.png"3030)   
           img_ornnament2.Bitmap = 
    LoadBitmapSample(File.DirAssets, "img_s/"& g&"_image.png"3030)
           img_ornnament3.Bitmap = 
    LoadBitmapSample(File.DirAssets, "img_s/"& g&"_image.png"3030)
           img_ornnament4.Bitmap = 
    LoadBitmapSample(File.DirAssets, "img_s/"& g&"_image.png"3030)
           img_ornnament5.Bitmap = 
    LoadBitmapSample(File.DirAssets, "img_s/"& g&"_image.png"3030)
      
    Next

       
    Log("five blocks")
       
    Next
     
  8. Sub7

    Sub7 Active Member Licensed User

    I feel stupid is just best work with an array of views. like tic tac toe example.
     
  9. klaus

    klaus Expert Licensed User

    Please explain what exactly you want to do !
     
  10. Sub7

    Sub7 Active Member Licensed User

    Sorry, i am trying to load 50 different images in a customlistview, five images each row.
    I have named the images in this way 0_image 1_image to concatenate the filename inside a loop.
     
  11. udg

    udg Expert Licensed User

    Do you want to arrange 50 elements on 10 rows of 5 items each?
    Something like?
    Code:
    for i= 0 to maxitems-1 'maxitems = 50
      row = floor(i/5)  ' 0,1,2,3,4,5,6,7,8,9
      col = i mod 5     ' 0,1,2,3,4
      log(row&" "&col)
    next
     
  12. klaus

    klaus Expert Licensed User

    Some thing like this:
    Code:
    For row = 0 to 9
        
    For col = 0 to 4
            ImageIndex = row * 
    5 + col
            ImageName = ImageIndex & 
    "_image"
        
    Next
    Next
     
  13. Sub7

    Sub7 Active Member Licensed User

    Yes thanks both. i am trying to arrange 50 elements on 10 rows of 5 items each.
    Tryng... :)
     
  14. Sub7

    Sub7 Active Member Licensed User

    I solved in this way

    Code:
    For x = 0 To p.NumberOfViews -1
       p.GetView(x).SetBackgroundImage(
    LoadBitmapSample(File.DirAssets, "img_s/"& x&"_image.png"3030))
    Next
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice