unreachable and dead code

why i am getting unreachable and dead code warning , i am not able to understant.
if anyone knows, please help me.

2 Kommentare

Image Analyst
Image Analyst am 24 Feb. 2026 um 19:42
I can't even read that thing. What is that diagram? Is it Stateflow or Simulink (which I don't have)? How did you run your check on it? You might have some condition that is always false, like
value = false
if value
% Do something if value = true
% This block will never get executed since value is not a variable,
% it's a constant.
end
VINAY
VINAY am 25 Feb. 2026 um 4:27
Now you can check

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 25 Feb. 2026 um 14:06

0 Stimmen

Before the Simulink funciton Counter_Check1() is called, there is this operation "Cnt=Cnt+CntTime1". Then, inside the function, there is this comparison "Cnt>=CntTime1". Maybe due to the fact that the value of "Cnt=InitValue" is zero or positive, the comparison "Cnt>=CntTime1" is always true.
So the "{%Do Nothing}" transition is never reached. It might be okay in terms of the logic, but in terms of software, it is regarded as "unreachable" or "dead code". It is not a good practice to have unreachable or dead code.
Change the "InitValue" to be negative to see if the warning disappear.

2 Kommentare

VINAY
VINAY am 25 Feb. 2026 um 15:09
hi @Fangjun Jiang i changed the "InitValue" To -ve eventhough warning is not dissppeared.
Fangjun Jiang
Fangjun Jiang am 26 Feb. 2026 um 15:51
You can attach your model here for others to try.

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2022a

Gefragt:

am 24 Feb. 2026 um 4:25

Kommentiert:

am 26 Feb. 2026 um 15:51

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by