Results 1 to 3 of 3
  1. #1
    MichYer is offline Member
    Join Date
    Jul 2007
    Posts
    6
    Rep Power
    0

    Exclamation A loop that doesn't loop

    Hi,
    I need another pair of eyes to glance at the following code.I am trying to create a bar chart and this code section is supposed to draw the bars in the chart. It draws the first dataset only.
    The inner loop works fine but the outer one does the first loop and then doesn't continue. Where is my error?
    Thanks
    Mich

    Java Code:
    if (chartType == 2)	{
    	int width = (barwidth/nSeries)/2;
    	int jump = 0;
    	for (int j=0;j<xTags;j++)
    	{
    	     curx = startx+jump;
    	     for(int i=0;i<=nSeries;i++)
    	     {
    	            cury = cHeight-((barheight*seriesIdata[i][j]/yJumps));
    		s2d.setColor(new Color(Integer.parseInt(seriesA[i]
    [1]),Integer.parseInt(seriesA[i][2]),Integer.parseInt(seriesA[i][3])));
    		s2d.fillRect(curx,cury,width,(barheight*seriesIdata[i]
    [j])/yJumps);
    		curx +=width*2;
    	     }
    		s2d.drawString(Integer.toString(curx),30,j*10);
    		jump += barwidth;
    	}
    }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Try to find out what's going on inside the outer loop:
    Java Code:
            for (int j = 0; j < xTags; j++) {
                System.out.printf("j = %d  xTags = %d%n", j, xTags);
                curx = startx + jump;

  3. #3
    MichYer is offline Member
    Join Date
    Jul 2007
    Posts
    6
    Rep Power
    0

    Default Thank you

    I had done so before and as I commented each line one by one and tried out various print outs I found that my problem was with the inner loop rather than the outer one.

    Mich

Similar Threads

  1. Loop Help
    By HeavyD in forum New To Java
    Replies: 7
    Last Post: 09-22-2010, 09:55 PM
  2. do...while loop
    By eva in forum New To Java
    Replies: 16
    Last Post: 01-31-2008, 06:44 AM
  3. while loop
    By michcio in forum New To Java
    Replies: 5
    Last Post: 01-27-2008, 12:56 AM
  4. can you help me with this for loop?
    By java_fun2007 in forum New To Java
    Replies: 6
    Last Post: 12-22-2007, 10:20 AM
  5. While loop
    By leebee in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 03:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •