Thread: (For) Loop

Results 1 to 4 of 4
  1. #1 (For) Loop 
    Registered Member
    Join Date
    Jan 2011
    Posts
    72
    Thanks given
    4
    Thanks received
    2
    Rep Power
    1
    Can somebody please explain what and how to use a (for) loop? I see it all the time but i'm not sure how to use it and i'd rather get the information from other coders.

    ex:
    Code:
    	for(int i; something.length, i++) {
    		if(i == potato[I][0]) {
    		potato = cheese[I][0]
    		}
    }
    Everyone is a leecher in some point of their runescape coding adventure.
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    just basically loops through a specified number, example:

    if you would like to count to ten, but not have to keep writing:

    System.out.println("1");
    System.out.println("2");
    //etc

    then you would simply do:

    for (int i = 0; i <= 10; i++) { //defining an int, starts at 0; the int is less than or equal to 10; everytime code below is complete, int goes up by 1 and repeat until the int has reached its max var (this case being 10).
    System.out.println(i); //printing out the number
    }
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member
    Join Date
    Jan 2011
    Posts
    72
    Thanks given
    4
    Thanks received
    2
    Rep Power
    1
    just basically loops through a specified number, example:

    if you would like to count to ten, but not have to keep writing:

    System.out.println("1");
    System.out.println("2");
    //etc

    then you would simply do:

    for (int i = 0; i <= 10; i++) { //defining an int, starts at 0; the int is less than or equal to 10; everytime code below is complete, int goes up by 1 and repeat until the int has reached its max var (this case being 10).
    System.out.println(i); //printing out the number
    }
    Thankyou, that was a damn good explanation lol
    Everyone is a leecher in some point of their runescape coding adventure.
    Reply With Quote  
     

  5. #4  
    Registered Member
    Join Date
    Jun 2011
    Posts
    220
    Thanks given
    3
    Thanks received
    13
    Rep Power
    2
    If you still need help, check this out. It really helped explain it to me. You can also look at other aspects of this site as it is good practice.
    CodingBat For While Loop
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. loop :(
    By Rugrats in forum Help
    Replies: 1
    Last Post: 08-25-2010, 09:02 AM
  2. Replies: 0
    Last Post: 08-24-2009, 12:14 AM
  3. For Each Loop
    By Scu11 in forum Snippets
    Replies: 14
    Last Post: 04-12-2009, 10:16 AM
Tags for this Thread

View Tag Cloud

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