java - Why is the "i++" a dead code here in the below snippet? -


while coding eclipse, code i++ shown dead code. mean? why being dead code?

public class scorecalculator{ public static void main(string[] args) {          int scorecard[] = {70,102,198, 60};         string playerslist[] = {"mukesh","suresh","shardul","nandan"};         system.out.println(displayscore(scorecard, playerslist));      }      public static string displayscore(int[] scores, string[] players){          for( int i=0; <= 3; i++){              if(scores[i]>100 && scores[i]<=200){                  system.out.println("\n******players moved next level******");                 return players[i] + "\n";             }             else             {                 system.out.println("\n******players in danger level******");                 return players[i] + "\n";             }          }         return "\n";     } } 

in possible flows exit loop before performing i++. there 3 different possible flows:

  1. you don't enter loop (just theoretical - in case enter).
  2. you enter , condition true - immediate return in if block.
  3. you enter , condition false - immediate return in else block.

in cases, don't finish single loop, code evaluated after each iteration, isn't reachable.

and for loop works following:

for (a; b; c)     ^^ - executes before loop starts (before first iteration         ^^ - evaluated before each iteration            ^^ evaluated after each full iteration, executed in case loop executes               @ least once 

personally, i'm impressed ide has spotted it.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -