Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Loop not working (JCreator)

    I have this code and whenever I run it, the applet viewer shows nothing. I have tried altering the running number as well as the counter. Any help is very appreciated.

    import java.awt.*;
    import java.awt.event.*;

    public class Unit103 extends java.applet.Applet {

    Graphics screen;
    int x,y,xmove,ymove,running;

    public void init() {
    x=135;
    y=220;
    xmove=1;
    ymove=1;
    running=1;
    }

    public void paint(Graphics screen) {

    while(running<1000000000);{
    screen.setColor(Color.green);
    screen.fillRect(x,y,50,50);
    for(int counter=1;counter<6000000;counter=counter+1){}
    screen.setColor(Color.white);
    screen.fillRect(x,y,50,50);
    if(x>350 || x<0);{
    xmove=xmove*-1;}
    if(y>350 || y<0);{
    ymove=ymove*-1;}
    x=x+xmove;
    y=y+ymove;
    running=running+1;
    }
    }
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This will run once: while(running<1000000000);. A semi-colon at the end of any branch is true once and only once.

  • Users who have thanked Fou-Lu for this post:

    Jamalrus (12-15-2011)


  •  

    Posting Permissions

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