0

any of can answer me why it print 0 to 8 why not 0-9

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { for (int i = 0; i < 10; i++) { if (i == 9 ) continue; Console.WriteLine(i); } } } }

11th Apr 2017, 10:17 PM
Muhammad Rehan Khan
Muhammad Rehan Khan - avatar
4 Respuestas
+ 5
you can see when the i reaches 9, the condition "i == 9" becomes true, so the if statement body is executed. continue means skip the rest of that iteration, so it skips the WriteLine. then "i" becomes 10 and the for loop is terminated
11th Apr 2017, 10:19 PM
Edward
+ 1
It's because you skip 9th iteration of loop using "continue".
11th Apr 2017, 10:19 PM
Jeth
Jeth - avatar
+ 1
Because when i == 9 skip the rest of the the iteration code with the continue sentence and continue with the next iteration if the for conditional comes true
11th Apr 2017, 11:38 PM
Ivan XXL
Ivan XXL - avatar
0
OK I understood thanks 😉
11th Apr 2017, 10:30 PM
Muhammad Rehan Khan
Muhammad Rehan Khan - avatar