View Poll Results: Vote For Your Favorite Loop Statement:

Voters
11. You may not vote on this poll
  • For

    8 72.73%
  • For Each

    1 9.09%
  • While

    2 18.18%
  • Do While

    0 0%
Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    [QUOTE=MK12;56482]
    Quote Originally Posted by Webuser View Post
    Java Code:
    for(15) { // loop 15 times
         s = change(); // SUPER PRETTY
         System.out.println(s); // BEAUTIFUL
    }
    hehe :D
    i like that, but it kinda breaks the rules of the for loop. for( ;; ){} OR for( : ){}
    OH! how could we forget the do keyword. (>,<)
    Java Code:
    do(15) { // loop 15 times & less typing.
         s = change(); // SUPER PRETTY
         System.out.println(s); // BEAUTIFUL
    }
    nobody uses do anyway...

    Here's a recent snipet from my codes. which one do you prefer?
    *you as in the reader...
    Java Code:
    // SUPER CONVENIENT FOR LOOP.
    
    for(BigInteger bIndex = cGen.size().subtract(ONE), 
        fIndex = BigInteger.ZERO
        ;// SEPARATOR
        cGen.isNotMiddle()
        ;// SEPARATOR
        bIndex = bIndex.subtract(BigInteger.ONE), 
        fIndex = forwardIndex.add(BigInteger.ONE)
        )
    { // START FOR LOOP
    
    
      // CODE HERE
      // this may look insane, 
      // but its very convenient..
    
    
    } // END FOR LOOP
    Java Code:
    BigInteger bIndex = cGen.size().subtract(ONE);
    BigInteger fIndex  = BigInteger.ZERO;
    while(cGen.isNotMiddle()){
    
      // CODE HERE
      // this may look sane, but you'll have to
      // keep scrolling up and down to find the
      // incrementor... (if your code is large).
    
      bIndex = bIndex.subtract(ONE);
      fIndex = forwardIndex.add(BigInteger.ONE);
    }
    Last edited by angryboy; 02-14-2009 at 10:25 AM.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  2. #22
    Join Date
    Oct 2008
    Posts
    73
    Rep Power
    0

    Smile

    my vote 4 ----
    while and for loop.....
    Rakesh Mehta

  3. #23
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    [QUOTE=MK12;56482]
    Quote Originally Posted by Webuser View Post
    And , what does i start at? once you put in these, you're back to the ordinary for loop. But for some cases, you don't need the i variable. consider this:
    Java Code:
    for(15) { // loop 15 times
         s = change(); // SUPER PRETTY
         System.out.println(s); // BEAUTIFUL
    }
    hehe :D
    And still here you'll have to use comething like i++ right in the loop body to get an iterator ho ho ho )
    so you'll must to modify the loop like for(15) to for(15:100) or something like that... It is not a critics but a live
    interest )
    Lets think it )

  4. #24
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default future of java?

    how about this...
    Java Code:
    decrement:
     do(15) { // means: i=0; do{i++}while(i<15);
       // CODE HERE
       // for codes w/o iterators.
       // 15 is inclusive or exclusive??
       // 0 is inclusive or exclusive??
     }
    
    increment:
     for(int i :10){ // means: i=0; i<10; i++
      // code here
     }
    
    which is similar to this:
    *
     int[] index={0,1,2,3,4,5,6,7,8,9};
     for(int i:index){
       System.out.println(i);
     }
    *thanks for the idea eranga ;)
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  5. #25
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Post do-while

    Java Code:
    String theNextString = file.readline(); // or whatever ...
    if( theNextString  != null) //
    {
        do
        {
             // do work here
             ;
             ;
             theNextString = file.readline(); // or whatever ...
         }
         while( theNextString  != null);
    }
    Then wrap in catch(NullPointerException);

    btw, just found this for your what editor thread:

    Some notes on text editors for Stata users
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Need help with a loop statement
    By sunshine39 in forum New To Java
    Replies: 7
    Last Post: 11-03-2008, 04:42 AM
  2. Least To Greates[ if statement and for loop]
    By kris09 in forum New To Java
    Replies: 1
    Last Post: 08-08-2008, 07:34 PM
  3. Beginner's Problem on Loop/If statement
    By obdi in forum New To Java
    Replies: 2
    Last Post: 07-07-2008, 02:41 AM
  4. Vote for my java bug
    By kjanz1899 in forum Java Applets
    Replies: 0
    Last Post: 06-29-2008, 06:29 PM
  5. Add Here Your Favorite Applets
    By M77 in forum Java Applets
    Replies: 4
    Last Post: 06-08-2008, 03:49 AM

Posting Permissions

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