ENGM 1081 Lecture Notes - Lecture 7: For Loop, In C
ENGM 1081 verified notes
7/29View all
Document Summary
Engm 1081 lecture 7 for loops. Whenever we seek to accomplish a task repeatedly, (for instance reading large amounts of data from a file; computing values; tallying sums; finding and replacing text in a document; etc) we can employ a loop. In c we have the for, while, and do-while loops. For and while loops and omit use of the do-while loop. Today we will focus on the for loop. Like the if-else structure, loops operate with the help of conditional statements. These take on the form of the expressions defined when a loop is written. In general, a for loop looks like for(expression 1; expression 2; expression 3){ Note: you must separate the three expressions with semi-colon"s (;) not commas (,) For example: int sum = 0; an integer sum variable int i; an integer counter variable for(i = 1; i<=10; i++){ Expression 1 -> initialization step i is set to start a 1.