C# TutorialLesson 18Free preview
C# For Loop
This lesson is part of C# · All levels
Summary
The iteration for combines the initialization, condition, and value addition in one line so that it is suitable for iterations with a fixed number. For can also be used to process two-dimensional data like tables or matrices. In addition, there is foreach to search the contents of the data set without manually managing the index.
Key points
- Structure for: initial, condition, then increment, written in a single pair of curves.
- The for control variable is made inside the curve so that its coverage is only on the loop.
- For a nest is used for two-dimensional structures such as rows and columns.
- Loop can start from another value, like 10 to 1 for counting backwards.
- To search the collection regardless of index, foreach is much more concise.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.