I was having a discussion with a stubborn person I know over which of these two forms was more semantically correct, although there is no logical difference to the code:  1.  for(int x = 0; x &lt; 10; x++) // do something   2.  for(int x = 0; x &lt; 10; ++x) // do something   Is it better to pre-increment or post-increment in a for loop?
12073
Is there a difference in ++i and i++ in a for loop? Is it simply a syntax thing?
53456
What is the difference between:  some_list1 = [] some_list1.append("something")   and  some_list2 = [] some_list2 += ["something"]
12628
Is there a benefit to using one over the other? In Python 2, they both seem to return the same results:  &gt;&gt;&gt; 6/3 2 &gt;&gt;&gt; 6//3 2
89868
In c#, is there any difference in the excecution speed for the order in which you state the condition?  if (null != variable) ... if (variable != null) ...   Since recently, I saw the first one quite often, and it caught my attention since I was used to the second one.  If there is no difference, what is the advantage of the first one?
29728
In other words, can I do something like  for() {     for {        for {        }     } }   Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?  Of course, the idea is that there should be an "easy" or "the usual" way of doing it. I already have an idea for a very complicated one.
34365
Which style is preferred? Is there a good reason for one vs. the other?  Thanks in advance!  1) cmds.each do |cmd|    end  2) cmds.each { |cmd|    }   Example code:  cmds = [ "create", "update", "list", "help" ]  # Block style one # cmds.each do |cmd|   puts "loop1, cmd: #{cmd}" end  # Block style two # cmds.each { |cmd|   puts "loop2, cmd: #{cmd}" }
1371
I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference?  A (quite pointless) example in Java:  a) declaration before loop:  double intermediateResult; for(int i=0; i &lt; 1000; i++){     intermediateResult = i;     System.out.println(intermediateResult); }   b) declaration (repeatedly) inside loop:  for(int i=0; i &lt; 1000; i++){     double intermediateResult = i;     System.out.println(intermediateResult); }   Which one is better, a or b?   I suspect that repeated variable declaration (example b) creates more overhead in theory, but that compilers are smart enough so that it doesn't matter. Example b has the advantage of being more compact and limiting the scope of the variable to where it is used. Still, I tend to code according example a.  Edit: I am especially interested in the Java case.
56680
I've seen both the blocks of code in use several different times, personally I have always used the first but my question is: is there a functional difference, and if there is what is it?  while (condition is true ) {     // do something }  do {     // do something } while ( condition is true);   I will be applying this to PHP but I assume this is fairly language agnostic.
109127
What is the purpose of the do keyword in Bash for loop syntax? To me, it feels redundant.  for i in `seq 1 2`; do echo "hi"; done   Why isn't the syntax like this?  for i in `seq 1 2`; echo "hi"; done   I'm sure that it does fill a purpose. I just want to learn.
13177
I have a questionable coding practice.   When I need to iterate through a small list of items whose count limit is under 32000, I use Int16 for my i variable type instead of Integer. I do this because I assume using the Int16 is more efficient than a full blown Integer.   Am I wrong? Is there no effective performance difference between using an Int16 vs an Integer? Should I stop using Int16 and just stick with Integer for all my counting/iteration needs?
110764
In the past and with most my current projects I tend to use a for loop like this:  var elements = document.getElementsByTagName('div'); for (var i=0; i&lt;elements.length; i++) {     doSomething(elements[i]); }   I've heard that using a "reverse while" loop is quicker but I have no real way to confirm this:  var elements = document.getElementsByTagName('div'),      length = elements.length;  while(length--) {     doSomething(elements[length]); }   What is considered as best practice when it comes to looping though elements in JavaScript, or any array for that matter?
11000
What is the difference between Parse() and TryParse()?  int number = int.Parse(textBoxNumber.Text);  // The Try-Parse Method int.TryParse(textBoxNumber.Text, out number);   Is there some form of error-checking like a Try-Catch Block?
114975
I need a list of integers from 1 to x where x is set by the user.  I could build it with a for loop eg assuming x is an integer set previously:  List&lt;int&gt; iList = new List&lt;int&gt;(); for (int i = 1; i &lt;= x; i++) {     iList.Add(i); }   This seems dumb, surely there's a more elegant way to do this, something like the
54334
Reading some books and posts I noticed that there are some semantice differences between constructions described in the title of this post. Could someone help me to find out what are the real difference and in which situations are better to use appropriate constructions?  I would be very grateful to hear the correct answer.
83035
The place is important for/to me.   I changed the variable for/to the project.   I can do to/for you.   In/for/to this project, I created a new method.      Does it mean any difference?  This bothered me many times.  Wish someone can answer.
12352
I just came onto a project with a pretty huge code base.   I'm mostly dealing with C++ and a lot of the code they write uses double negation for their boolean logic.    if (!!variable &amp;&amp; (!!api.lookup("some-string"))) {        do_some_stuff();  }                                      I know these guys are intelligent programmers, it's obvious they aren't doing this by accident.   I'm no seasoned C++ expert, my only guess at why they are doing this is that they want to make absolutely positive that the value being evaluated is the actual boolean representation. So they negate it, then negate that again to get it back to its actual boolean value.   Is this correct, or am I missing something?
4327
Is there a way in Java's for-each loop  for(String s : stringArray) {   doSomethingWith(s); }   to find out how often the loop has already been processed?  Aside from using the old and well-known for(int i=0; i &lt; boundary; i++) - loop, is the construct  int i = 0; for(String s : stringArray) {   doSomethingWith(s);   i++; }   the only way to have such a counter available in a for-each loop?