0

Can anyone explain me something in C#?

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 = 1; while(num < 6) { Console.WriteLine(num); num+=2; } } } }

17th May 2018, 12:34 PM
Bogdan Văduva
Bogdan Văduva - avatar
21 Answers
17th May 2018, 1:01 PM
Scooby
Scooby - avatar
+ 6
i suggest complete java,c# like course in sololearn .. then you have some idea ..
17th May 2018, 1:18 PM
Scooby
Scooby - avatar
+ 5
here at initialize time num=1. a while check num<6 its mean when num==6 or more than that while break. in while block a print function which print current value of num and num increase by 2 at each while loop.. output is 1 3 5
17th May 2018, 12:49 PM
Scooby
Scooby - avatar
+ 4
so why you post ur question "can anyone explain me this fuction?" i did what u want Bogdan Văduva
17th May 2018, 12:56 PM
Scooby
Scooby - avatar
+ 2
I understood this... thanks
17th May 2018, 1:28 PM
Bogdan Văduva
Bogdan Văduva - avatar
+ 1
and what can i do with this ? :)) i don' understand, i know this function output 1 3 5 ...
17th May 2018, 12:52 PM
Bogdan Văduva
Bogdan Văduva - avatar
+ 1
it will print 1,3,5 on the console
17th May 2018, 1:05 PM
Mohsen Saleh
Mohsen Saleh - avatar
+ 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 6 namespace SoloLearn { class Program { static void Main(string[] args) { int num = 0; while(num < 6) { Console.WriteLine(++num); num++; } } } } That's what I discovered by myself when I tested different variants and I'm trying to see what results I give, with this can have the same result ... is not it good?
17th May 2018, 1:06 PM
Bogdan Văduva
Bogdan Văduva - avatar
+ 1
i know the output of this ... 1 3 5... but I do not understand how you can apply it and why, give me examples in what you can use? or in a program?
17th May 2018, 1:08 PM
Bogdan Văduva
Bogdan Văduva - avatar
+ 1
in frist step in line while(num<6) num compare to 6 and checks num must smaller then 6 then enter while body and print num value then num value adds 2 and them go to first line and check again while condition and if conditon is true the previous step will repate...
17th May 2018, 1:11 PM
Mohsen Saleh
Mohsen Saleh - avatar
+ 1
thank you for explaining, I'm sorry to say this but I already knew. I want an example, how can you apply it to a program and how it helps the program, what results in the program ... An example of a program to which this work is applied and what does it do you have?
17th May 2018, 1:15 PM
Bogdan Văduva
Bogdan Văduva - avatar
+ 1
in programming we have some base part like loops ,condition statment, ... in loop we can itrate on list or e.g in the real world we want bring out all of karpet in house we can not bring all of them in one time we should repate bringing out to all of them put out like real world some times we need to repate something in programming that we use loops
17th May 2018, 1:19 PM
Mohsen Saleh
Mohsen Saleh - avatar
+ 1
java and c # are the same? thank you...
17th May 2018, 1:19 PM
Bogdan Văduva
Bogdan Văduva - avatar
+ 1
we can doing same thing in c# or java ways
17th May 2018, 1:20 PM
Mohsen Saleh
Mohsen Saleh - avatar
+ 1
for example how can you compute sum of 1 to 1000? you should use loop
17th May 2018, 1:24 PM
Mohsen Saleh
Mohsen Saleh - avatar
+ 1
int num =1; while(num<=1000) { num++; } console.writeline(num);
17th May 2018, 1:27 PM
Mohsen Saleh
Mohsen Saleh - avatar
0
no, with this int num = 1; while(num < 6) { console.writeline(num); num+=2; } with this... and num+=2 is not num = num + 2? i know the main function ... you need this for all programs it's of the program or something like that, no? sorry for my english, i don't speak very good...
17th May 2018, 12:57 PM
Bogdan Văduva
Bogdan Văduva - avatar
0
if you give me an example of what I need to repeat and for what I'm doing ... you're the best :))
17th May 2018, 1:23 PM
Bogdan Văduva
Bogdan Văduva - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 6 namespace SoloLearn { class Program { static void Main(string[] args) { int num = 0; while(num < 1000) { Console.WriteLine(++num); num++; } } } } That's what I discovered by myself when I tested different variants and I'm trying to see what results I give, with this can have the same result ... is not it good? or change console.writeline(++num); with console.writeline(num++) and this give from 0 to 998 from first rezult 1,3,5,7....
17th May 2018, 1:29 PM
Bogdan Văduva
Bogdan Văduva - avatar