Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explaining the concepts of Label (break and continue) in Dart #6451

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

J-Manoj-06
Copy link
Contributor

This PR improves the Dart documentation by adding detailed explanations and examples for the break and continue statements in various loop structures (for, while, do-while, and nested loops).

The changes have made in two directories:

  1. /examples/language/lib/control_flow/branches.dart

  2. /src/content/language/branches.md

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
  • This PR doesn't contain automatically generated corrections or text (Grammarly, LLMs, and similar).
  • This PR follows the Google Developer Documentation Style Guidelines — for example, it doesn't use i.e. or e.g., and it avoids I and we (first person).
  • This PR uses semantic line breaks of 80 characters or fewer.

This ensures and follows the contributing guidelines.
As per the issue , the Labels in Dart is explained with examples. Waiting for further improvements.

Fixes (#6289)

Best regards,
Manoj J

@J-Manoj-06 J-Manoj-06 mentioned this pull request Feb 22, 2025
1 task
@antfitch antfitch self-requested a review February 26, 2025 00:28
@antfitch
Copy link

Thank you for this contribution! It looks like the staging docs did not build. Can you build the docs on your local machine and use the validator to validate your changes? https://github.com/dart-lang/site-www?tab=readme-ov-file#validate-your-changes

@J-Manoj-06
Copy link
Contributor Author

Yeah sure mam,
The documentation is in the progress!!
Thank you.

@antfitch
Copy link

Yeah sure mam, The documentation is in the progress!! Thank you.

Welcome and I can't wait to see the final version!

@antfitch
Copy link

/gcbrun

@dart-github-bot
Copy link
Collaborator

dart-github-bot commented Feb 26, 2025

@J-Manoj-06
Copy link
Contributor Author

Thank you, ma'am , That means a lot!

Copy link

@samujjal-gogoi samujjal-gogoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the issue , the Labels in Dart is explained with examples. Waiting for further improvements.

Fixes (#6289)

You haven't explained about label in this PR yet.

@antfitch antfitch marked this pull request as draft February 27, 2025 21:17
@antfitch
Copy link

Converted this to a draft. When it's ready for review, let us know. ^_^

@J-Manoj-06
Copy link
Contributor Author

Sorry for the delay mam!!
My semester exams is going on . So managing both creates some difficulties for me.
By tomorrow I will be updating the request.
Best regards,
Manoj J

@J-Manoj-06
Copy link
Contributor Author

Hello @antfitch mam,
I have updated the documentation in both branches.md and branches.dart directories. Please review it.
Waiting for further improvements.
Thank You.
Best Regards,
Manoj J

@J-Manoj-06
Copy link
Contributor Author

As per the issue , the Labels in Dart is explained with examples. Waiting for further improvements.
Fixes (#6289)

You haven't explained about label in this PR yet.

Hello @samujjal-gogoi ,
I have updated the branches directories.
Please make a review and I'm waiting for the improvements.
Thank you.
Best Regards ,
Manoj J

@@ -138,6 +138,240 @@ switch (command) {
}
```

### Labels in Dart

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Labels in Dart
### Labels

Simple heading is preferred.


In Dart, labels are used to control nested loops(Loop inside Loop) using break and continue. Labels allow you to specify which loop to `break` or `continue`, rather than affecting the innermost loop by default.

Here is the syntax for labels in Dart :

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Here is the syntax for labels in Dart :
Here is the syntax for labels in Dart:

Avoid space between the word and : (I've found multiple occurrences, please find and fix them all).

@@ -138,6 +138,240 @@ switch (command) {
}
```

### Labels in Dart

In Dart, labels are used to control nested loops(Loop inside Loop) using break and continue. Labels allow you to specify which loop to `break` or `continue`, rather than affecting the innermost loop by default.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In Dart, labels are used to control nested loops(Loop inside Loop) using break and continue. Labels allow you to specify which loop to `break` or `continue`, rather than affecting the innermost loop by default.
In Dart, labels are used to manage control flow in nested loops using `break` and `continue` statements. They allow you to specify which loop to break out of or continue, rather than affecting the innermost loop by default.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quote string over double-quote string.


```

In the above example, When `i == 2` and `j == 2`, `break outerLoop;` statement stops both inner and outer loops. So, the expected output would be :

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the above example, When `i == 2` and `j == 2`, `break outerLoop;` statement stops both inner and outer loops. So, the expected output would be :
In the above example, when `i == 2` and `j == 2`, `break outerLoop;` statement stops both inner and outer loops. So, the expected output would be:

Besides this, I've found multiple occurrences, please find and fix them all.


```

#### Labels in for loop using `contiue` :

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Labels in for loop using `contiue` :
#### Labels in for loop using `continue`:

Found a typo!

}

```
In the above example, the iteration for i = 2, j = 2 is skipped, and the loop moves directly to i = 3. As a result, the output would be:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the above example, the iteration for i = 2, j = 2 is skipped, and the loop moves directly to i = 3. As a result, the output would be:
In the above example, the iteration for `i = 2` and `j = 2` is skipped, and the loop moves directly to `i = 3`. As a result, the output would be:

Looks like you forgot to wrap the values with backticks?


```

In the above example, the loop skips i = 2, j = 2 and moves directly to i = 3. As a result, the output would be:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the above example, the loop skips i = 2, j = 2 and moves directly to i = 3. As a result, the output would be:
In the above example, the loop skips `i = 2` and `j = 2` and moves directly to `i = 3`. As a result, the output would be:

Same backticks issue here as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing all unnecessary leading and trailing newlines in code blocks.

@samujjal-gogoi
Copy link

Also, consider documenting Labels in loops.md file over branches.md file as it suits better there.

@J-Manoj-06
Copy link
Contributor Author

Also, consider documenting Labels in loops.md file over branches.md file as it suits better there.

Sir, would you like me to document Labels in loops.md instead of branches.md? Please confirm.
Thank you for your valuable suggestions, @samujjal-gogoi sir!

@samujjal-gogoi
Copy link

Also, consider documenting Labels in loops.md file over branches.md file as it suits better there.

Sir, would you like me to document Labels in loops.md instead of branches.md? Please confirm. Thank you for your valuable suggestions, @samujjal-gogoi sir!

Yes, at the end of the file (i.e after Break and continue section).

@J-Manoj-06
Copy link
Contributor Author

Okay, @samujjal-gogoi sir.
I'll notify you once the update is done.
Thank you.

@J-Manoj-06 J-Manoj-06 marked this pull request as ready for review March 3, 2025 15:45
@J-Manoj-06
Copy link
Contributor Author

Hello @samujjal-gogoi sir,
I have considered and updated all you suggestions . And it is ready for review.
Also waiting for further suggestions for improvements.
Thank You.
Best Regards,
Manoj J

Copy link

@samujjal-gogoi samujjal-gogoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great so far!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single quotes to satisfy the lint.

- prefer_single_quotes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing all unnecessary leading and trailing newlines in code blocks.

@antfitch
Copy link

antfitch commented Mar 3, 2025

/gcbrun

Added editorial changes.
@antfitch
Copy link

antfitch commented Mar 3, 2025

Looking good! @J-Manoj-06, I've added editorial changes. Next, you'll need to connect the changes you made in examples/language/lib/control_flow/loops.dart to src/content/language/loops.md

In src/content/language/loops.md, take a close look at the source code in the For loops section. You'll notice they all start with <?code-excerpt "language/test/control_flow/..."?>

You want to add this line above all of your new samples and then generate the code excerpts to make sure that they run. If you have any issues, check out this doc: https://github.com/dart-lang/site-shared/tree/main/pkgs/excerpter#readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants