Expand iteration module content with detailed explanation Addresses …#1711
Expand iteration module content with detailed explanation Addresses …#1711saikrishna488 wants to merge 1 commit intoCodeYourFuture:mainfrom
Conversation
…ssue CodeYourFuture#1706: Expand description of array iteration Adds comprehensive content including: - Introduction to iteration as a general programming concept - Detailed explanation of the 'for' loop syntax and execution - Information about alternative loop types - Real-world examples and use cases Added comprehensive overview of iteration, including definitions, examples, and various loop types in JavaScript.
👷 Deploy request for cyf-curriculum pending review.Visit the deploys page to approve it
|
👷 Deploy request for cyf-piscine pending review.Visit the deploys page to approve it
|
👷 Deploy request for cyf-common pending review.Visit the deploys page to approve it
|
👷 Deploy request for cyf-sdc pending review.Visit the deploys page to approve it
|
👷 Deploy request for cyf-itd pending review.Visit the deploys page to approve it
|
👷 Deploy request for cyf-tracks pending review.Visit the deploys page to approve it
|
👷 Deploy request for cyf-launch pending review.Visit the deploys page to approve it
|
Poonam-raj
left a comment
There was a problem hiding this comment.
Hi Sai, thank you for your contribution, really nicely expanded on.
Some comments left about bits that just need signposting, deleting or rewording now we have this additional section.
Plus the code snippets could do with a comment in them to show output just to increase clarity to students.
Thanks!
| 1. Initialize the counter variable (happens once) | ||
| 2. Check the condition | ||
| 3. If the condition is true, execute the code in the loop body | ||
| 4. Execute the increment/update statement |
There was a problem hiding this comment.
just refer to "increment statement" on point 4 to avoid confusion
| ```javascript | ||
| let i = 0; | ||
| while (i < 5) { | ||
| console.log(i); | ||
| i++; | ||
| } | ||
| ``` |
There was a problem hiding this comment.
Can you add in a commented indicator of what the log will output? Again just do this for the rest of the code snippets included here
Just so students can immediately see the result of the loop
| ```javascript | ||
| const numbers = [10, 20, 30]; | ||
| for (const number of numbers) { | ||
| console.log(number); | ||
| } |
There was a problem hiding this comment.
Can you add in a commented indicator of what the log will output?
| ```javascript | ||
| for (let i = 0; i < 3; i++) { | ||
| console.log(i); | ||
| } |
There was a problem hiding this comment.
Can you add in a commented indicator of what the log will output?
| ### The `for...in` Loop | ||
|
|
||
| The `for...in` loop iterates over the properties of an object (including inherited ones): | ||
|
|
||
| ```javascript | ||
| const person = { name: 'Alice', age: 30, city: 'London' }; | ||
| for (const key in person) { | ||
| console.log(key + ': ' + person[key]); | ||
| } | ||
| ``` | ||
|
|
||
| **Note:** For arrays, use `for...of` instead of `for...in`, as `for...in` includes inherited properties. | ||
|
|
There was a problem hiding this comment.
I appreciate the compehensiveness of including for...in but in this case as objects haven't been touched on yet for students I think avoiding confusion and not introducing object syntax too soon will be helpful. Please remove for...in from this page.
Ideally we would have a section in sprint 2 of this module (where objects is interested) where we discuss iteration again but in the context of a for...in loop.
| Iteration is a universal programming concept that you'll use constantly. Start by mastering the `for` and `for...of` loops, as these are the most common and fundamental. As you progress, you'll learn when and how to use the other loop types and array methods, each suited to different situations and coding styles. | ||
|
|
||
|
|
||
| To solve the sub-goal, we have to repeatedly add each number in the array to the `total`, one at a time. In programming, the process of repeating something is called **iteration**. |
There was a problem hiding this comment.
Add a subheading to indicate we're back into solving the sub-goal. "Continuing with CalculateMean" or "Solving the sub-goal" or similar.
| In programming, we can **iterate** by using a {{<tooltip title="loop">}}A loop is a sequence of instructions that is continually repeated until some condition is reached.{{</tooltip>}}. | ||
|
|
||
| In particular, we can use a [`for...of` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) to sum the elements of the array. |
There was a problem hiding this comment.
Re-work this wording, now we have explained iteration this feels a bit janky and needs to flow on better from your addition above.
…issue #1706: Expand description of array iteration Adds comprehensive content including: - Introduction to iteration as a general programming concept - Detailed explanation of the 'for' loop syntax and execution - Information about alternative loop types - Real-world examples and use cases
Added comprehensive overview of iteration, including definitions, examples, and various loop types in JavaScript.
What does this change?
Common Content?
Common Theme?
Issue number: #issue-number
Org Content?
Module | Sprint | Page Type | Block Type
Checklist
Who needs to know about this?