About 50 results
Open links in new tab
  1. What is the difference between i++ & ++i in a for loop?

    The way for loop is processed is as follows 1 First, initialization is performed (i=0) 2 the check is performed (i < n) 3 the code in the loop is executed. 4 the value is incremented 5 Repeat steps 2 - 4 …

  2. In detail, how does the 'for each' loop work in Java?

    The Java for each loop (aka enhanced for loop) is a simplified version of a for loop. The advantage is that there is less code to write and less variables to manage.

  3. What is the syntax of the enhanced for loop in Java?

    Mar 2, 2017 · 44 I have been asked to use the enhanced for loop in my coding. I have only been taught how to use traditional for loops, and as such don't know about the differences between it and the …

  4. java - How does a for loop work, specifically for (;;)? - Stack Overflow

    Jul 23, 2015 · loop body: The body of the loop, which will be executed again and again based on the conditional check's truth value. Basically this is how the execution follows - first, when the loop is …

  5. What is the easiest/best/most correct way to iterate through the ...

    Jan 6, 2017 · Some ways to iterate through the characters of a string in Java are: Using StringTokenizer? Converting the String to a char[] and iterating over that. What is the …

  6. java - Declaring variables inside or outside of a loop - Stack Overflow

    Jan 10, 2012 · The scope of local variables should always be the smallest possible. In your example I presume str is not used outside of the while loop, otherwise you would not be asking the question, …

  7. How do I get the current index/key in a "for each" loop

    16 In Java, you can't, as foreach was meant to hide the iterator. You must do the normal For loop in order to get the current iteration.

  8. Is there a shorter way to write a for loop in Java?

    0 In many cases max value is unknown (data from files, databases etc.). For me the best is loading everything to List (ArrayList etc.) and use for-each loop. Looping through collections is the best way …

  9. How do I exit a while loop in Java? - Stack Overflow

    Oct 31, 2011 · 2 Take a look at the Java™ Tutorials by Oracle. But basically, as dacwe said, use break. If you can it is often clearer to avoid using break and put the check as a condition of the while loop, …

  10. A for-loop to iterate over an enum in Java - Stack Overflow

    A for-loop to iterate over an enum in Java Asked 16 years, 7 months ago Modified 2 years, 3 months ago Viewed 543k times