+ 1
C# loop more efficient in while leasson
On the while loop lesson where it shows you about while loop I would make the code shorter to make sure the same mission Int num = 1; While (num < 6){ Console.WriteLine(num++); } Done :)
4 odpowiedzi
+ 2
But why? shorter doesn't necessarily mean more readable. Even as it is now, people still find some issues in dealing. IMO shorter code is no good idea when it will only discourage new learners.
+ 1
There is not much difference between for and while loops. the for loops can be called a enhanced form of while loops.
The for loop structure:
for(declearation; condition; postLoopCounter) {
//Code
}
The while loop structure:
while(condition) {
//Code
}
In terms of effeciency, there doesnt seem to be much difference between for and while loops.
But, obviously, the for loops make our code shorter, and easily debug-able.
+ 1
Ipang
It completely depends on code.
On basic counter loops, while loops are not suitable.
On non-numerical and multiple conditional loops, for loops work, but not considered as good as while loops.
+ 1
Sarthak 🇳🇵
I wrote that for the OP buddy, not to your response.
I have to disagree on the idea to "compress" snippets especially those used as introductions and/or learning materials. And more specifically, when the most of code readers are new learners, like here in SL.
What did you mean by "non-numerical" and "multiple conditional" loops? how come `while` loop excels over `for` loop for these types of loop?
Also, why "On basic counters, while loops are not suitable."