Download presentation
Presentation is loading. Please wait.
1
Structured Program Development in C
Dr. Nouf Aljaffan Nouf Aljaffan (C) 2018
2
Iteration & Looping Nouf Aljaffan (C) 2018
3
Means of iteration: Counter-Controlled Iteration
Sentinel-controlled iteration definite iteration It requires The name of a control variable (or loop counter). The initial value of the control variable. The increment (or decrement) by which the control variable is modified each time through the loop. The condition that tests for the final value of the control variable (i.e., whether looping should continue). indefinite iteration The precise number of iterations isn’t known in advance, and The loop includes statements that obtain data each time the loop is performed. Nouf Aljaffan (C) 2018
4
Iteration & Looping Nouf Aljaffan (C) 2018
5
While Iteration Statements
Initialization While( condition){ statements } Nouf Aljaffan (C) 2018
6
While Iteration Statements
Nouf Aljaffan (C) 2018
7
for Iteration Statement
Nouf Aljaffan (C) 2018
8
for Iteration Statement
Nouf Aljaffan (C) 2018
9
do…while Iteration Statement
Nouf Aljaffan (C) 2018
10
break and continue Statements
break and continue are used to alter the flow of control. Nouf Aljaffan (C) 2018
11
break Statement break can be used in a while, for, do…while or switch statement causes an immediate exit from that statement. Program execution continues with the next statement after that while, for, do…while or switch. Nouf Aljaffan (C) 2018
12
continue Statement continue can be used in a while, for or do…while
Cause skipping the remaining statements in that control statement’s body and performs the next iteration of the loop. Nouf Aljaffan (C) 2018
13
Confusing Equality (==) and Assignment (=) Operators
Nouf Aljaffan (C) 2018
14
Logical Operator Logical AND (&&) Operator Logical OR (||) Operator
Logical Negation (!) Operator Nouf Aljaffan (C) 2018
15
Exercises Sum the odd integers between 1 and 99 using a for statement. Use the unsigned integer variables sum and count. Print the integers from 1 to 20 using a while loop and the counter variable x. Print only five integers per line. [Hint: Use the calculation x % 5. When the value of this is 0, print a newline character, otherwise print a tab character.] Nouf Aljaffan (C) 2018
16
Conclusion Variables Data Types
Expression represent a single data item such as a number or character Statement caused the computer to carry out some action Branching If statement If..Else statement Nested if statement Switch statement Looping For statement While statement Do while statement Nouf Aljaffan (C) 2018
17
Questions? Nouf Aljaffan (C) 2018
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.