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

Obsolete While...Wend loop inspection #4522

Closed
retailcoder opened this issue Nov 15, 2018 · 3 comments
Closed

Obsolete While...Wend loop inspection #4522

retailcoder opened this issue Nov 15, 2018 · 3 comments
Assignees
Labels
difficulty-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspection-quickfixes feature-inspections up-for-grabs Use this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky

Comments

@retailcoder
Copy link
Member

The While...Wend construct was made obsolete with the introduction of Do While...Loop blocks, forever ago. Rubberduck should have an inspection that flags them, and a quickfix that replaces While...Wend with Do While...Loop.

Obsolete While...Wend loop
'While...Wend' loops cannot be prematurely exited without a 'GoTo' statement. Use the equivalent and more modern 'Do While...Loop' construct instead, which can be exited with an 'Exit Do' statement.

Therefore, a further enhancement (involving a bit of code path analysis) could look for a line label/number immediately after Wend:

While foo
    DoSomething foo
    If bar = 42 Then GoTo ExitWhile
Wend
ExitWhile:
'...

...and replace it with an Exit Do statement:

Do While foo
    DoSomething foo
    If bar = 42 Then Exit Do
Loop
'...

(removing the line label/number if it's left unreferenced)

@retailcoder retailcoder added enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections up-for-grabs Use this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky difficulty-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. feature-inspection-quickfixes labels Nov 15, 2018
@bclothier
Copy link
Contributor

Bonus: If it's While Not foo, convert to Do Until foo instead. Let's encourage people to not double-negative themselves!

@Inarion
Copy link
Contributor

Inarion commented Nov 15, 2018

Linking chat for context. :)

@retailcoder
Copy link
Member Author

Just to clarify - a first iteration/implementation of the inspection+quickfix can very well just flag While...Wend and replace with Do While...Loop without altering the rest of the code/logic. The rest is nice-to-have, cherry-on-top sugar.

@retailcoder retailcoder self-assigned this Mar 17, 2019
retailcoder added a commit to retailcoder/Rubberduck that referenced this issue Mar 17, 2019
IvenBach pushed a commit to IvenBach/Rubberduck that referenced this issue May 13, 2019
@Vogel612 Vogel612 added this to Done in Release 2.4.2 Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty-02-ducky Resolving these involves the internal API, but with relatively easy problems to solve. enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspection-quickfixes feature-inspections up-for-grabs Use this label in conjunction with a difficulty level label, e.g. difficulty-02-ducky
Projects
No open projects
Release 2.4.2
  
Done
Development

No branches or pull requests

3 participants