"Z Code Writer" is an Online Blog for Programmer & Beginner. Here, You will Find tech, Build your Programming Skills and other Programming Language Like C, C++, HTML, Java Script Java Code, Web Designing and University Of Sialkot (USKT) CGPA / GPA Calculator etc.

Sunday, 26 July 2020

Explain Loops

What is Loop?

            A method or mechanism through which a statement or a set of statements of program can be executed again and again (repeat) that is called loop. The body of loop can be executed again and again for a given number of times.

Loop Statements

            Loop statement are used to execute a statement or a set of statements again and again. Loops are the most important function of any programming language. Loop Statement is also known as iterative structure or repetitive structure. When we need to use loop we must need to tell the system starting number and ending number to execute yhe loop statement otherwise it may give error or infinite loop.

Types of Loop Statements in C

        In C/C++ language there are three types of loop statements.
  1. 'while' loop
  2. 'do-while' loop
  3. 'for' loop

Control Variable

        Any variable which is used in loop statement to control the number execution or flow in the loop that is known as loop control variable. Usually, we initialize variable at before the body of loop because it will be see where the loop statement will be execute first.  

'while' Loop

        'while' loop is a conditional loop structure in programming language. It is used to execute a statement or a set of statements as long as the given condition remains true. This loop structure is used when the programmer does not know in advance the number of repetition of loop.
The general syntax of 'while' structure is as follows:
                  while (condition)
                           statement ;
                  next_statement ;

The syntax of 'while' structure for a group of statements is as follows:
                   while (condition)
                  {
                            group of statements ;
                   }
                   next_statement ;

Flowchart of 'while' Loop

Following is the flowchart of 'while' loop structure:
While-loop-diagram
While loop diagram



No comments:

Post a Comment

Thanks For Visiting Here...!! I will Reply you as soon as possible.