Monday 24 February 2020

Loop in C Language - tccicomputercoaching.com


What is Loop in Programming?

To write once, but execute more than one time is called Loop in Programming. This will save time of developer to write n time.

3 type of Loop:


  •  for
  •  while
  •  do-while


We see one by one in detail.

There are 3 sections in each loop:

there is loop variable i/j

1. initialization i=1 or i=10

2. condn check i<=10 or i>=1

3. update (++ or --) i=i+1 or i++ i--

e.x. We want to print 10 time "hello world". Then what is the syntax in coding?

Let us see.

1. for loop

for (i=1;i<=10;i++)

{

Printf ("hello world\n");

}

Here, all 3 sections are in same statement. First initialization executed always. Then control goes to the condition checking. If condition is true then only control entered into the loop and statement inside the loop will be executed. Then control goes to the updating, again condition checking , and same process will continue until condition will be false.

2. While Loop

i=1;
   
while(i<=10)

{
 
printf ("hello wolrd\n");

i++;

}

Here , initialization is outside of Loop. Then control goes to the condition checking. If condition is true then only control entered into the loop and statement inside the loop will be executed. Then control goes to the updating, again condition checking , and same process will continue until condition will be false.

3. do -while Loop

i=1;

do

{
 
printf ("hello wolrd\n");

i++;
 


} while (i>=10);

Here, also initialization is outside of Loop. But in this Loop condition is last , so control direct enter into the loop and one time statement inside the loop will be executed. Then updating and last control rich to the condition checking. If condition is true then control again entered into the loop , and process will be continue until condition will be false.

Thus , Do - While loop is different than previous two loop. Here condition is last , so , if condition is false yet output will execute one time. When in previous two loop condition is false then output will not execute once.

Second difference is : in do-while there is semi colon at last.

TCCI is located in developing area of city - Bopal and heart of City Satellite area in Ahmedabad.
Our course include all Computer course, Web Designing Course , Project Training, Basic Computer Course, Programming Course etc.

We have team of qualified and experienced Faculties who teach all important subjects of Civil Engineering, Mechanical Engineering, Computer-IT Engineering, EC Engineering, Electrical Engineering, EEE Engineering , Maths Course etc

We teach computer subjects to school students from class 1 to 12th (any Board).

Main advantage of TCCI is "Lecture as per student flexible time".

For more information about TCCI.

Call us @ 9825618292

Visit us @ http://tccicomputercoaching.com/

No comments:

Post a Comment