0
because I always shows "0"
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) { int num = 0; while(num < 6) Console.WriteLine(num); num++; } } }
5 ответов
+ 4
Because you forgot the curly braces for the while loop. The corrected code:
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)
{
int num = 0;
while(num < 6)
{
Console.WriteLine(num);
num++;
}
}
}
}
+ 1
To add to James's answer; we are allowed to omit curly braces only if the syntax within is on 1 line.
Here's and example, notice that my second 'if' statement has no curly braces:
http://www.sololearn.com/app/csharp/playground/cF71B5FwjdfU/
0
thanx for comments .
0
great !! Malachi thanx for your comments
0
when your code is more than 1 line you must put your code between the braces