CHAPTER 4 : Looping Statements

Definition

Looping is a sequence of instructions that is continually repeated until a certain condition is reached .

A loop is a way of repeating a statement a number of times until some way of ending the loop occurs .

3 types of looping statements

FOR

WHILE

DO-WHILE

Define Loop Statement

For : Programming language statement which allows code to be repeatedly executed

While : Control flow statement

Do-while : Control flow statement

Break Statements

Statement allows you to exit a loop from any point within its body,bypassing its normal termination expression

Used in conjuction with functions and case statements which have been covered in previous session

Continue Statements

Cause control to go directly to the test condition and then continue the looping process

One good use of Continue is a to restart a statement sequence when an error occurs

Goto Statements

Create a loop by jumping backwards to a label though this is generally discouraged as a bad programming practice

Differentiate the loop statements

WHILE : Loop the condition is tested first and then the statements are executed if the condition turn out to be true

DO-WHILE : 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

FOR : Allowing us to repeat certain parts of the program until a specified number of repetitions - allows to determine the required number of repetitions