Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 4 Looping Statement - Coggle Diagram
Chapter 4
Looping Statement
Define Looping Statement
Looping is a sequence of instructions that is continually repeated until a certain condition is reached.
List types of Looping Statement
for
while
do-while
Define FOR, WHILE, DO-WHILE loop statement.
• A FOR loop is a programming language statement which allows code to be repeatedly executed.
A WHILE loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.
• A DO-WHILE loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given Boolean condition at the end of the block.
Identify the need for BREAK, CONTINUE and GOTO statements.
• It is generally best to use the break for special purposes, not as your normal loop exit.
• One good use of CONTINUE is to restart a statement sequence when an error occurs.
• Using a label, a Goto Statement can also create a loop by jumping backwards to a label though this is generally discouraged as a bad programming practice.
Describe the structure of FOR, WHILE, DO-WHILE loop statements
• FOR statements are often used to process lists such a range of numbers.
• This process repeats until test expression is false.
Structure of WHILE loop statement
• A DO-WHILE loop runs at least once even though the the condition given is false
• In a WHILE loop the condition is first tested and if it returns true then it goes in the loop
Entry Control Loop
• In a DO-WHILE loop the condition is tested at the last - exit control loop
The while statement is used to carry out looping operations, in which a group of statement is executed repeatedly, until some condition has been satisfied
The WHILE construct consists of a block of code and a condition/expression.
DO-WHILE loops are useful for things that want to loop at least once.
Construct program(s) that use FOR, WHILE, DO-WHILE loop statements.
multiple loop control variable
Construct program(s) that use BREAK and GOTO statements
BREAK in FOR loop
Write a C program to find average of maximum of n positive numbers entered by user. But, if the input is negative, display the average(excluding the average of negative input) and end the program
Though, using GOTO statement give power to jump to any part of program, using GOTO statement makes the logic of the program complex and tangled