rspec/rules/S1716/python/rule.adoc
2022-02-04 16:28:24 +00:00

42 lines
895 B
Plaintext

``++break++`` and ``++continue++`` are unstructured control flow statements which make code harder to read. Additionally, more recent versions of Python raise a SyntaxError when modules containing ``++break++`` or ``++continue++`` outside of a loop are imported.
Therefore, these statements should not be used outside of loops.
== Noncompliant Code Example
[source,python]
----
narg=len(sys.argv)
if narg == 1:
print('@Usage: input_filename nelements nintervals')
break
----
== Compliant Solution
[source,python]
----
if narg == 1:
print('@Usage: input_filename nelements nintervals')
sys.exit()
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]