"(For ... : ...)" How to

Discussion in 'Plugin Development' started by BloodShura, Jan 21, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    BloodShura

    Hi.

    I want know, how I use (For...), for each value in a integer. Ex:

    Integer n = 5;

    For (i : n) {
    ///
    }

    This is, for each "one" in the integer, will execute the thing. Example: if "n" equals 5, will execute five times.

    Can someone help me? D:
     
  2. Offline

    theguynextdoor

    Code:java
    1. for(int n = 0; n < 5; n++){
    2. Bukkit.getServer().broadcastMessage("this is message " + n);
    3. }


    That would repeat say the message 5 times.

    The for loop with the : like you asked first is an enhanced forloop or a for each loop and is used for iterable objects or arrays.
     
    BloodShura likes this.
  3. Offline

    BloodShura

    Thanks, that's it! :)

    +Like
     
  4. Offline

    mb01

    I don't mean to be rude buy why you don't look for a Java tuto / book? If you don't know how to use a for loop you'll have a lot of question about general programing.
     
  5. Offline

    ItsHarry

    I agree with mb01, you should learn JAVA before starting to make plugins :)
     
Thread Status:
Not open for further replies.

Share This Page