because I always shows "0" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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++; } } }

29th Jun 2016, 3:07 PM
Karlos Uriarte Castro
Karlos Uriarte Castro - avatar
5 Answers
+ 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++; } } } }
29th Jun 2016, 3:44 PM
James Flanders
+ 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/
29th Jun 2016, 9:36 PM
Malachi Jones
Malachi Jones - avatar
0
thanx for comments .
29th Jun 2016, 3:49 PM
Karlos Uriarte Castro
Karlos Uriarte Castro - avatar
0
great !! Malachi thanx for your comments
30th Jun 2016, 2:52 AM
Karlos Uriarte Castro
Karlos Uriarte Castro - avatar
0
when your code is more than 1 line you must put your code between the braces
30th Jun 2016, 9:51 PM
Artemis Ariamehr
Artemis Ariamehr - avatar