Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 4 Looping Statements - Coggle Diagram
Chapter 4
Looping Statements
4.1.1 Define Looping Statement
Looping is a sequence of instructions that
is continually repeated until a certain
condition is reached.
4.1.2 List types of Looping Statement
There are 3 types of looping statements:
FOR
WHILE
DO-WHILE
4.1.3 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.
4.1.4 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.
4.1.5 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.
4.2 Structure of WHILE loop
statement
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.
• 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
4.3 Apply the looping
statements
4.3.1 Construct program(s) that use FOR,
WHILE, DO-WHILE loop statements.
multiple loop control variable
4.3.2 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