c# - I dont understand my own code -


lets user wants calculate multiplication table of number, line want. user inputs in 2 , inputs in 10. console writes out multiple ten. code don't understand why have set int counter = -1, instead of 0.

try {     console.writeline("the number of lines want calculate ");     int loops = convert.toint16(console.readline());     if (loops <0)     {          console.writeline("can not enter value less zero... try again?");          console.readline();          goto start;     }     console.writeline("what multiplication tables ?");     int m = convert.toint16(console.readline());     (int counter = -1; counter <= loops; counter+=1)     {         (int mt = m; mt >= 0; mt += m)         {             if (mt % m == 0)             {                 counter += 1;                 if (counter == loops)                 {                     break;                 }                                         }                                                             console.writeline(mt);         }     }     console.readline(); } catch {     console.writeline("enter numbers only");     console.readline();     goto start; } 

your incrementing before check counter why have start counter @ -1.

  if (counter == loops)   {        break;   }        counter += 1; //move below if statement 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -