Friday, July 29, 2016

C Basics - Loops in C

A loop executes a set of instructions repeatedly. This involves repeating some portion of the program either a specified number of times or until a particular condition is being satisfied. This repetitive operation is done through a loop control instruction.

A loop statement allows us to execute a statement or group of statements multiple times. The general form of a loop statement is,

STEP 1: Execute conditional code
STEP 2: Check condition. If true, go to STEP 1. If false, go to STEP 3.
STEP 3: Exit

Following are the methods by way of which we can repeat a part of a program. They are
Using a for statement: Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

Using a while statement: Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.

Using a do-while statement: It is more like a while statement, except that it tests the condition at the end of the loop body.

nested loops: You can use one or more loops inside any other while, for, or do..while loop.



Related topics:
The for Loop in C   |   The while Loop in C   |   The do-while Loop in C   |   Nested Loop in C   |   Infinite Loop in C   |   Loop Control Statements in C   |   The break Statement in C   |   The continue Statement in C   |   The goto Statement in C   |   The return Statement in C

List of topics: C Programming

No comments:

Post a Comment