basic code
posted 8 years ago
please give a line by line explaination.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
please give a line by line explaination.
posted 8 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Welcome to CodeRanch Ankita!
When you post code, surround it with [code] and [/code] so that it appears nicely formatted. You can use the "Preview" button to check that your post looks okay before you submit it. I have added code tags for you this time.
When you post code, surround it with [code] and [/code] so that it appears nicely formatted. You can use the "Preview" button to check that your post looks okay before you submit it. I have added code tags for you this time.
Stephan van Hulst
Bartender
Posts: 15743
368
posted 8 years ago
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Stephan van Hulst
Bartender
Posts: 15743
368
posted 8 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Note that the for-loop is confusing, because it performs an assignment in the loop condition expression. The following would be more clear:
I've renamed the array because the loop is more easily readable now.
Note that x starts with 1, thereby skipping the first element of the array. I don't know if this was the intention of the original program.
I've renamed the array because the loop is more easily readable now.
Note that x starts with 1, thereby skipping the first element of the array. I don't know if this was the intention of the original program.
posted 8 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The statement in the tutorial about for loop execution isn't clear about when the middle expression is evaluated:
It would be clearer if it said the expression was evaluated BEFORE the loop was started. It is stated in the language specifications.
That means that the ++x is executed BEFORE the loop starts giving x an initial value of 1.
When the termination expression evaluates to false, the loop terminates.
It would be clearer if it said the expression was evaluated BEFORE the loop was started. It is stated in the language specifications.
That means that the ++x is executed BEFORE the loop starts giving x an initial value of 1.
posted 8 years ago
Not sure I understood you correctly, but for now it doesn't sound right.
For loop contains statements, they are executed in order starting from left to right as they would be written from top to down.
Did I understand correctly, that you say line 2 gets executed before line 1?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Norm Radder wrote:That means that the ++x is executed BEFORE the loop starts giving x an initial value of 1.
Not sure I understood you correctly, but for now it doesn't sound right.
For loop contains statements, they are executed in order starting from left to right as they would be written from top to down.
Did I understand correctly, that you say line 2 gets executed before line 1?
posted 8 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
For the reference what tutorials actually say:
I might know what you mean, that it doesn't say explicitly that every time it gets evaluated when loop iterates. Well, probably authors imply that word "loop" already explains that. And not to get confused, the first statement says that initialization happens only once.
Oracle Java Tutorials wrote:The initialization expression initializes the loop; it's executed once, as the loop begins.
When the termination expression evaluates to false, the loop terminates.
The increment expression is invoked after each iteration through the loop; it is perfectly acceptable for this expression to increment or decrement a value.
I might know what you mean, that it doesn't say explicitly that every time it gets evaluated when loop iterates. Well, probably authors imply that word "loop" already explains that. And not to get confused, the first statement says that initialization happens only once.
Norm Radder
Rancher
Posts: 5146
38
posted 8 years ago
I meant to say that the termination expression is evaluated BEFORE any statements in the loop are executed. That means the ++x is executed BEFORE the loop starts and gives x a value of 1 for the first time through the loop.
I was referring to the original code:
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Not sure I understood you correctly, but for now it doesn't sound right.
I meant to say that the termination expression is evaluated BEFORE any statements in the loop are executed. That means the ++x is executed BEFORE the loop starts and gives x a value of 1 for the first time through the loop.
I was referring to the original code:
posted 8 years ago
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Welcome to code ranch,
(I know that it's already a bit too late to ask, since people have already given an explanation for the code ...)
Why do you need an explanation for that piece of code ?
Why would you name a class "_" and have variables with names like "$", "__A_V_" ?
Although your topic states "Basic code", I would term it as horrible code
It would be a nightmare for someone to maintain code that looks like this.
(I know that it's already a bit too late to ask, since people have already given an explanation for the code ...)
Why do you need an explanation for that piece of code ?
Why would you name a class "_" and have variables with names like "$", "__A_V_" ?
Although your topic states "Basic code", I would term it as horrible code
It would be a nightmare for someone to maintain code that looks like this. Ankita Mittal
Greenhorn
Posts: 2
posted 8 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Stephan van Hulst wrote:
Thank you
| what if we put solar panels on top of the semi truck trailer? That could power this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |










