Join Gerry O'Brien for an in-depth discussion in this video Solution: Count to 10, part of Up and Running with C#.
In the challenge for creating a for loop, you were asked to create one…that counted to 10 and output the value of the counter to the console window.…I'll demonstrate one way of performing this.…We know that when we're creating a for loop, we start off…with the keyword for and open…our parentheses to include the appropriate parameters.…We need an initialization portion.…And in this case, I'm going to create something…called counter and I initialize my counter to 0.…Next, I want to verify that I want my counter or my loop to count up to the…value of 10, so I will put my conditional in that says counter less than 10.…
And then I will complete my for loop header…signature by putting my increment portion with a counter++.…Once I've completed that, I can open my curly braces…and then begin to write the body of my for loop.…And in this case, all we wanted to do…was output to the console window using the Console.WriteLine…method and simply putting in the counter variable to…have Visual Studio output the information to the console window.…
- Installing C#
- Working with loops
- Controlling program flow
- Using variables
- Building functions
- Creating and instantiating classes
- Catching errors
- Managing resources with the garbage collector
- Building collections
Skill Level Beginner
1. Introducing C#
2. C# Language Elements
3. Object-Oriented Programming in C#
4. Structured Exception Handling
5. Resource Management in C#
6. Extensible Types in C#
7. Windows Apps in C#
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.