Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 4: LOOPING STATEMENTS - Coggle Diagram
Chapter 4: LOOPING STATEMENTS
DEFINITON
A loop is a way of repeating a statement a number of times until some way of ending the loop occurs
Looping is a sequence of instruction that is continually repeated until a certain condition is reached
TYPES OF LOOPING STATEMENT
FOR
A programming language statement which allows code to be repeatedly executed
WHILE
A control flow statement that allows code to be executed repeatedly based on a given Boolean condition
DO-WHILE
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
DIFFERENTIATE THE LOOP STATEMENTS
FOR
Statement for allowing us to repeat certain parts of the program until a specified number of repetitions - allow to determine the required number of repetitions.
WHILE
Tested first and then the statements are executed if the condition turns out to be true.
In a while loop, the condition is first tested, and if it returns true then it goes in the loop - entry control loop
DO-WHILE
The statements are executed for the first time and then the conditions are tested, if the condition turns out to be true then the statements are executed again
A do-while loop runs at least once even though the condition given is false
GOTO STATEMENTS
Can create a loop by jumping backwards to label through this is generally discourage as a bad programming pratice.
C PROVIDES TWO COMMANDS TO CONTROL HOW WE LOOP
CONTINUE
In WHILE & DO-WHILE loops, it will cause control to go directly to the test condition and then continue the looping process
It forces the next iteration of the loop to take place, skipping any code in between itself and the test condition of the loop
In FOR, the increment part of the loop continues
BREAK
When the break statement is encountered inside a loop, the loop is immediately terminated, and program control resumes at the next statement following the loop.
Can be used with all 3 of C's Loops
Exit for loop or switch