Loops

Looping Statements:
If any process has to be repeated for finite or infinite number of times until the condition evaluates to false is considered as looping or iteration

Loop Type Description
while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.
do…while loop Like a while statement, except that it tests the condition at the end of the loop body
for loop Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.
nested loops You can use one or more loop inside any another while, for or do..while loop.

While Loop:
It is a pre-tested loop construct.
The condition is evaluated before the body of the loop gets executed

while(condition)
{
statement(s);
}

  • Body of the loop can have more than one statement
  • {} braces should be provided for multi-statement
  • Including braces for individual statements increases readability


null

Mr. Sandeep Soni

Founder, Trainer & CEO, Deccansoft Software Services.

Sandeep has 21 yrs of experience working in various Microsoft Technologies/Platforms incl. VB6.0, ASP, VC++, VB.NET, C#. He is involved in managing and architecting projects at Deccansoft. He will be your liaison to Deccansoft, for any kind of communication and project updates. He knows what works and what doesn’t, and what practices are most suitable for design and programming with the ultimate goal of producing a quality system.