Computer Science, asked by fathima9286, 1 year ago

Explain about pre test loop and post test loop in c language

Answers

Answered by nhkmk786
2
while Loop:

The simplest of all the looping structure in c' is the while statement. The basic format of the while statement is :

Syntax:

         while  (condition)

           {

               body of loop

           }


The while is an "entry controlled loop" statement. The  test condition is evaluated and if the condition is True, then the body of the loop is executed. After execution of the body, the test condition is once again evaluated  and if it is true, the body is executed once again. This process of repeated until the test condition finally becomes false and the control is transferred out of the loop. On exit, the program continues with the statement immediately after the body of the loop.


The body of the loop may have one or more statements. The braces are needed only if the body contains two or more statements. However it is a good practice to use braces even if the body has only statement.


Example :-


void main()

{

   int a;

   a=1;

  while (a<=10)

  {

    printf(" % d \n ", a);

      a=a+1;

  }

getch();



Answered by Hansika4871
1

The pre-test loop and post-test loop in c language are defined as:

  • Pre-test loop: Before executing each statement within the loop, the Test Condition is evaluated. The loop statements never execute if the test condition is false. It's also known as top testing. For example, for and while.
  • Post-test loop: After running all statements within the loop, the Test Condition is evaluated. The loop statements are executed once even if the test condition is false. It is also called bottom testing. For example, do while.

Similar questions