|
||||||
| CSharp Tutorials Tutorials for C# |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||||
|
Looping in C# - Part 2 By Xav Following on from my other tutorial, http://forum.codecall.net/c-tutorial...looping-c.html, here we will discover the other three types of loop: while,foreach,do while. The Foreach Loop This loop is very useful, as it cycles through every object in an ObjectCollection. For every iteration of the loop, there is a local variable available which contains the current object. Here is the syntax: csharp Code:
csharp Code:
The While/Do While Loop The while loop executes until a certain condition is met. It takes the following syntax: csharp Code:
csharp Code:
csharp Code:
csharp Code:
Differences between While and Do While There is one main difference between the Do and Do While loops - the Do loop always executes at least once, as the condition is at the bottom, not the top. However, there is a chance that the Do While loop may never execute at all. Bear this in mind when writing your code. Test yourself: Add some controls to a form. Write a program that cycles through all the controls, and displays the name of each one to the user in a message box. Hint: Use the Form.Controls[] ObjectCollection. Another hint: It's an object collection... Hope this helps! Xav P.S. If this was helpful, please +rep. Leave any comments/suggestions/praise below! |
| Sponsored Links |
|
|
| Sponsored Links |
|
|
|
|||||
|
Not a bad tutorial. Again, I like the test yourself portion. It seemed like a fair enough length to me but I did read it on my mobile.
![]() I will give +rep in the morning. Posted via CodeCall Mobile |
|
|||||
|
Just received the rep. Thanks!
I know LogicKills' negative rep didn't leave a massive dent, but it's the principle. For my <script language="php"> 'tutorial' I received +rep, and it wasn't more than 5 mins' worth of work. It's not about length, it's about usefulness. Anyway, you requested this based on the other tut, which I didn't receive rep for, so this was just a follow-up in the series. ![]() But if I'm going to lose reputation points whenever I post a tutorial, then maybe I'll just stop writing them... ![]() |
|
|||||
|
I agree it isn't about the time spent or length. In fact, some newb may find this extremely helpful, however, he does have the right to give you -rep just as I gave you +rep.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages! |
|
|||||
|
I know he has the right, but it's not very encouraging in terms of how likely I am to give up some of my time to write a tutorial...
... but he (or she - I didn't read his Introduction thread) has a rep power of 1, and you have a rep power of 50, so... I'm not too fussed. ![]() |
|
|||||
|
Well.. I got like 5 or so reps with the power of 0, so should I start whining because I didn't receive any rep points although they gave me +rep? Nope... just live with it!
My articles in the security forum are over 1000 words long.. and I don't receive any +rep for them (since the only ones I receive are of power 0) I don't care. I write tutorials because I know I can give the community something, not because of a +rep! But still... quite a good and basic tutorial. +/- rep from me so that evens out.. so basically.... I shouldn't even press the button ![]() Everyone happy! |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|