Content Obsolete

This content is no longer current. Our recommendation for up to date content:

for Iterations - 08

Download this episode

Download Video

Download captions

Download Captions


Iterations allow our applications to loop through a block of code until a condition is satisfied. We'll cover several different types of iteration statements throughout this series, starting with the for iteration statement. This lesson demonstrates how to utilize "code snippets" to help remind you of the syntax for this complex statement, and shows debugging in action via the values of loops displayed in the Visual Studio IDE.

Download the source code for Iterations


C#, Visual Studio



Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image


    • User profile image

      Great video series Bob.

      Here's a nice homework challenge for this lesson that ties back to the lessons on data types.

      Challenge: Modify Bob's code so that the numbers displayed are 1-10 instead of 0-9. Don't forget to modify when 7 is found. I found several ways to do it wrong before I figured out a correct method.


    • User profile image

      many ways to do it, not sure what way your talking about...

    • User profile image

      many ways to do it, not sure what way your talking about...

      A way that returns the correct result Wink The point being to try it as it reinforces earlier concepts.

      For example:


      Will give you something different. 

    • User profile image

      Nice One Smiley

    • User profile image

      Easiest way to get it to display 1 - 10 is to alter the "for" loop.

    • User profile image

      What i wish was explained is why are parenthesis used by themselves vs when do parenthesis rest inside another pair of parenthesis? i.e... console.writeline(message); vs console.writeline (i.toString()); don't think I heard this explained.

    • User profile image

      @Skyeblue: First of all, KUDOS for being an "active learner" ... for having questions about the content and not just accepting the order I'm presenting the content.  I am an active learner too ... I have to "control" the learning process by asking questions.  So, again, you're doing it right.  Smiley

      Specifically to your question ... You might want to re-watch Lesson 7 on operators wherein I say that the parenthesis operator plays several roles, but when butted right up next to an identifier (like a method name) means that it is used as the method invocation operator ... so:


      ... will EXECUTE the method.  

      In the examples you used:

      console.writeline()  <--- here we're invoking the writeline method of the console object

      i.ToString() <--- here we're invoking the ToString method of integer objects

      What the heck does all that mean?  In Lessons 10 and 15 we'll talk about methods more.  So, we're getting there!!!  Just hang in there.  Smiley

    • User profile image

      You say thank you at the end of each video, but I should be thanking you!
      So far so good! I'm still rusty on a few things, but with practice, I'm sure I'll get better!

    • User profile image

      @Tyler: Smiley  Thanks for the kind words.

    • User profile image

      Dear Bob,

      First off: your lessons are great! Thank you for that.
      Secondly I still don't understand why there is an ToString in Console.WriteLine(i.ToString) and with the myX example it is not there.
      I recreated your examples and all seems to work either with or without ToString. I am not sure if this is the same question SkyeBlue asked, but I don't think so. Maybe the answer to my question become clear as well later on?

    • User profile image

      O nevermind, Bob, I see you answered my question already below video 9. :)

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.