Lecture26 - ComputerProgrammingITAC162. Now moves to...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 08 Mar 2006 Now moves to Looping Iteration in C for statement while statement do-while statement
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Computer Programming I TA C162 . 08 Mar 2006 Basics of loops 1. Initialization of a condition variable. 2. Execution of the loop statements. 3. Test for a specified value of the condition variable. 4. Updating the condition variable. C provides three constructs for loop operations The for statement The while statement The do –while statement
Background image of page 2
3 Computer Programming I TA C162 . 08 Mar 2006 for Statement Structure: for (init; test-condn; incr/decr) { loop_body; } Loop body can have a single statement or a group of statements. init test loop_body updation F T
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Computer Programming I TA C162 . 08 Mar 2006 Executes loop body as long as test evaluates to TRUE (non-zero). 1. Initialization 2. Conditional Testing 3. Updation of loop control variable Either 1 or 2 or 3 or ALL of them can be optional Note: Test is evaluated before executing loop body. for Statement Cont…
Background image of page 4
5 Computer Programming I TA C162 . 08 Mar 2006 for : Single statement sum = 0; for (i = 1; i <= 10; i++) sum + = i; i = 1; sum = 0; for ( ; i <= 10; i + = 1) sum + = i; i = 1; sum = 0 for ( ; i < 10 ; ) sum + = i++;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Computer Programming I TA C162 . 08 Mar 2006 More Examples i=1; sum = 0; for( ; ; ) sum + = i++; How many times loop statement will be executed? for ( i = 0,j = 7 ; i < j; i++, j-- ) printf(“%d”,i); for (i = 0,j = 7; i < j; i++, j--); printf(“%d %d”,i,j); Output???
Background image of page 6
7 Computer Programming I TA C162 . 08 Mar 2006
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

Lecture26 - ComputerProgrammingITAC162. Now moves to...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online