C TutorialLesson 16Free preview
C For Loop
This lesson is part of C · All levels
Summary
For loops are the most commonly used iteration structures when the number of iterations is known. The definition is divided into three parts within a line: the counter initialization, the stop condition, and the counter value addition. The three parts are separated by semicolon and all can be emptied as needed. For makes the calculator code more concise and easy to read than writing while separately.
Key points
- Structure for: for (inisialisasi; kondisi; penambahan) { ... }
- The condition is evaluated before each iteration; when it is wrong, the loop ends.
- The use of for is very suitable for index-based iterations such as arrays
- The third part supports i++, i--, i+= steps, or other expressions.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.