Зачем в цикл do while добавлять инкремент например? (Это в языке C#) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Зачем в цикл do while добавлять инкремент например? (Это в языке C#)

Вот код: int x = 1; do { x++; Console.WriteLine(x); } while(x < 3); Объясните пожалуйста, зачем добавлять x++? Я знаю что чтобы цикл был не бесконечен но как это работает?

22nd Mar 2021, 1:12 PM
‎أندريه‎
‎أندريه‎ - avatar
2 Answers
+ 1
I didn't understood your language if u asking for Output explanation here your initial value of x is 1 then it will run till upto x<3 when execution will start inside do while there is x++ Here x will incremet by 1 so x=2 console writeline will print 2 then it will check condition 2<3 this is true again loop will run and x++ here x will be 3 and it Will print then 3<3 which is false so execution will stop here . And finally u will get output 23
22nd Mar 2021, 5:14 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Many thanks! Good luck writing your code
22nd Mar 2021, 8:29 PM
‎أندريه‎
‎أندريه‎ - avatar