Legacy code: break in if block without a loop [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
-1
down vote

favorite












I am a beginner in shell scripting and I am working on a legacy project where I need to maintain/enhance the shell scripts.
I came across the following code block in a shell script.



if [ some_condition ]; then
do_something
break
else
if [ some_condition ]; then
do_some_other_thing
exit 1
fi
fi


As you can see, there are no loops involved here and original author uses break in the if block!
As I am doing enhancement, I thought of changing it to



if [ some_condition ]; then
do_something
else
if [ some_condition ]; then
do_some_other_thing
exit 1
fi
fi


Questions:
I believe, break in the original code is a bad coding. Am I correct? If not what is the use of it there in the block?







share|improve this question











closed as off-topic by Stephen Rauch, Sam Onela, Imus, Dannnno, Mast Apr 6 at 14:29


This question appears to be off-topic. The users who voted to close gave these specific reasons:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Sam Onela, Dannnno, Mast

  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Stephen Rauch, Imus

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 3




    I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    – Dannnno
    Apr 6 at 13:30
















up vote
-1
down vote

favorite












I am a beginner in shell scripting and I am working on a legacy project where I need to maintain/enhance the shell scripts.
I came across the following code block in a shell script.



if [ some_condition ]; then
do_something
break
else
if [ some_condition ]; then
do_some_other_thing
exit 1
fi
fi


As you can see, there are no loops involved here and original author uses break in the if block!
As I am doing enhancement, I thought of changing it to



if [ some_condition ]; then
do_something
else
if [ some_condition ]; then
do_some_other_thing
exit 1
fi
fi


Questions:
I believe, break in the original code is a bad coding. Am I correct? If not what is the use of it there in the block?







share|improve this question











closed as off-topic by Stephen Rauch, Sam Onela, Imus, Dannnno, Mast Apr 6 at 14:29


This question appears to be off-topic. The users who voted to close gave these specific reasons:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Sam Onela, Dannnno, Mast

  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Stephen Rauch, Imus

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 3




    I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    – Dannnno
    Apr 6 at 13:30












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am a beginner in shell scripting and I am working on a legacy project where I need to maintain/enhance the shell scripts.
I came across the following code block in a shell script.



if [ some_condition ]; then
do_something
break
else
if [ some_condition ]; then
do_some_other_thing
exit 1
fi
fi


As you can see, there are no loops involved here and original author uses break in the if block!
As I am doing enhancement, I thought of changing it to



if [ some_condition ]; then
do_something
else
if [ some_condition ]; then
do_some_other_thing
exit 1
fi
fi


Questions:
I believe, break in the original code is a bad coding. Am I correct? If not what is the use of it there in the block?







share|improve this question











I am a beginner in shell scripting and I am working on a legacy project where I need to maintain/enhance the shell scripts.
I came across the following code block in a shell script.



if [ some_condition ]; then
do_something
break
else
if [ some_condition ]; then
do_some_other_thing
exit 1
fi
fi


As you can see, there are no loops involved here and original author uses break in the if block!
As I am doing enhancement, I thought of changing it to



if [ some_condition ]; then
do_something
else
if [ some_condition ]; then
do_some_other_thing
exit 1
fi
fi


Questions:
I believe, break in the original code is a bad coding. Am I correct? If not what is the use of it there in the block?









share|improve this question










share|improve this question




share|improve this question









asked Apr 6 at 10:03









NJMR

1384




1384




closed as off-topic by Stephen Rauch, Sam Onela, Imus, Dannnno, Mast Apr 6 at 14:29


This question appears to be off-topic. The users who voted to close gave these specific reasons:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Sam Onela, Dannnno, Mast

  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Stephen Rauch, Imus

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Stephen Rauch, Sam Onela, Imus, Dannnno, Mast Apr 6 at 14:29


This question appears to be off-topic. The users who voted to close gave these specific reasons:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Sam Onela, Dannnno, Mast

  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Stephen Rauch, Imus

If this question can be reworded to fit the rules in the help center, please edit the question.







  • 3




    I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    – Dannnno
    Apr 6 at 13:30












  • 3




    I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
    – Dannnno
    Apr 6 at 13:30







3




3




I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Dannnno
Apr 6 at 13:30




I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Dannnno
Apr 6 at 13:30










1 Answer
1






active

oldest

votes

















up vote
1
down vote













The break statement is used to exit the current loop before its normal ending so, in this case, it is useless.






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    The break statement is used to exit the current loop before its normal ending so, in this case, it is useless.






    share|improve this answer

























      up vote
      1
      down vote













      The break statement is used to exit the current loop before its normal ending so, in this case, it is useless.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        The break statement is used to exit the current loop before its normal ending so, in this case, it is useless.






        share|improve this answer













        The break statement is used to exit the current loop before its normal ending so, in this case, it is useless.







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 6 at 12:36









        Andrea Girardi

        1193




        1193












            Popular posts from this blog

            Chat program with C++ and SFML

            Function to Return a JSON Like Objects Using VBA Collections and Arrays

            Will my employers contract hold up in court?