Legacy code: break in if block without a loop [closed]
Clash 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?
shell ksh
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
add a comment |Â
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?
shell ksh
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
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
add a comment |Â
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?
shell ksh
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?
shell ksh
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
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
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
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
The break statement is used to exit the current loop before its normal ending so, in this case, it is useless.
answered Apr 6 at 12:36
Andrea Girardi
1193
1193
add a comment |Â
add a comment |Â
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