What is the difference between the following two pieces of code




















Let's work to help developers, not make them feel stupid. Related Questions. Threading and parallelization for the given snippets. Why the two following C code differ by output?

Convert the following jquery code to typescript. What is the problem of this snippet. How to add two different collectionviews with xibs in first and second cell of tableview. Assigning ranking based on difference in two rows in a SQL table.

Needed an old code snippet. I have a code snippet that I'm not sure how to write. Layout: fixed fluid. Web02 2. Strip HTML. Encode HTML. Paste as-is. Michael: Yes, variables declared inside a loop effectively behave differently to those declared outside a loop, in terms of capture. C 5 just changed whether the foreach iteration variable counted as "inside" or "outside". Show 1 more comment. Active Oldest Votes. Instead of expression like: seq. I am bit confused over here when the OP uses int y the last value is captured which is But how does that explain output to be 30?

No, in the second example variable is 2, 3 and then 5. Only 30 is dividible by all of these numbers. Variable y is defined inside the loop code block, so lamba uses different value for every iteration. Add a comment. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. DIF Data Interchange format. DOC or. FM3 Filemaker Pro databases the numbers following represent the version.

HTM or. HTML Web page source text. MAC MacPaint. MAP Web page imagemap. MID or. MOV or. MTB or. MTW MiniTab. PDF Acrobat -Portable document format. PPT or. Primarily, a single "block" comment should be placed at the top of the function or file and describe the purpose the code and any algorithms used to accomplish the goal. In-line comments should be used sparingly, only where the code is not "self-documenting". When you do use "in-line" comments, you should place them before or next to any code that is not self explanatory.

This comment should detail the "idea" behind the code and what is to be accomplished. It may also say how this is to be accomplished if the "algorithm" is complex. In line comments are those that are found in the general body of the program.

They are usually very short a line or two comments making a "note" about what is going on. In line comments are usually made using the "single line" commenting syntax of the language. You should add "in-line" comments wherever you think a little bit of English explanation would be useful to either yourself or someone else like a TA who is going to read your code. Such in-line comments should be used whenever the code is not "transparent" easy to follow simply from the names of the variables.

See the section below on self documenting code, which allows a programmer to minimize the number of necessary comments. Self documenting code uses well chosen variable names and function names to make the code read as close to English as possible. This should be your goal. For example, naming a variable g has little meaning, but naming a variable gravity gives a much better description of what the variable should contain.

By using proper variable and function names, you should minimize the amount of "external" documentation that is necessary. For example, compare the following two pieces of code? File Header comments are used to identify what is in a file, who wrote it, the date it was written, and a description of what is being solved by the code in the file.



0コメント

  • 1000 / 1000