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

New Rule: no obsolete jump statements #49

Closed
silviomarghitola opened this issue Jun 5, 2019 · 3 comments
Closed

New Rule: no obsolete jump statements #49

silviomarghitola opened this issue Jun 5, 2019 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@silviomarghitola
Copy link

Language Usage / Control Structures / Flow Control
Avoid using jump statements that direct the flow to the default direction

from SonarQube

Jump statements should not be redundant

Jump statements, such as RETURN and CONTINUE let you change the default flow of program execution, but jump statements that direct the control flow to the original direction are just a waste of keystrokes.

Noncompliant Code Example

CREATE PROCEDURE print_numbers AS
BEGIN
  FOR i in 1..4 LOOP
    DBMS_OUTPUT.PUT_LINE(i);
    CONTINUE;
  END LOOP;
  RETURN;
END;

Compliant Solution

CREATE PROCEDURE print_numbers AS
BEGIN
  FOR i in 1..4 LOOP
    DBMS_OUTPUT.PUT_LINE(i);
  END LOOP;
END;
@PhilippSalvisberg
Copy link
Collaborator

If we say we should not use GOTOs (see G-4310) and RETURNs (see G-7430) only at the end of a function, then we should also avoid using CONTINUE.

Hence I'm thinking about changing the rule to not use CONTINUE at all. Thoughts?

@PhilippSalvisberg PhilippSalvisberg added enhancement New feature or request help wanted Extra attention is needed labels Jun 5, 2019
@rogertroller
Copy link
Collaborator

An unconditional continue does not make sense at all...but other usages of continue are ok imho. Otherwise you would have either:

  • lenghty if / else constructs
  • raises and exception handler to skip an iteration
    and here continue is much easier

@PhilippSalvisberg
Copy link
Collaborator

So you suggest to change the rule to

Never use unconditional CONTINUE statements

Right? Do you have a good example where CONTINUE makes sense?

@kibeha kibeha closed this as completed in 0eeb731 Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants