Thread: Chapter03
View Single Post
  #3 (permalink)  
Old February 14th, 2016, 07:17 PM
BraneTronics BraneTronics is offline
Authorized User
Points: 129, Level: 2
Points: 129, Level: 2 Points: 129, Level: 2 Points: 129, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb No problem with the code!

First of all the code that you mentioned is in page 67 of my printed version of the book. Weird??? I don't see any problem with the code you mentioned either. The authors are trying to explain how the do...while loop works. The code in the book prints numbers 1 to 10 like it is supposed to.

If you are confused by the use of "{0}", i++ instead of $"{i}",i++ then both of these are valid C# code. Use of $"{i}",i++ being the latest C# 6.0 feature.

Try copying the code within -------- in visual studio and try it out.
-------------------------------------------------------------------------------
using System;

namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
int i = 1;
do
{
Console.WriteLine("{0}",i++);
} while(i <= 10);

Console.ReadKey();
}
}
}
----------------------------------------------------------------------------------
// Prints out
1
2
3
4
5
6
7
8
9
10

Hope this helps you understand how do...while loop works!
Reply With Quote