Monday, May 18, 2015

what is Do-While loop

what is Do-While loop
It is also exit control loop. The condition is checked after executing the body of loop. That means the loop will be executed at least once.Do while loop is similar to while loop,however there is once basic difference do while run atleast once even if the test condition if false.Do-while loop is also called exit controlling loop.The condition comes after the body . Even the condition is false initially.
Syntax :-
                {
                                Statement;
                                Statement;
                                Increase/decrement;
                }
                While (condition);<semi column is needed.

Let us take one example to print square of even number from 1 to 50.
                Int main()
{
                Int i= 1;
                Do
                {
                If (i%2 == 0)
                {
                Printf(“%d/t”,i*i);
                }
                i+I;
                }
                While (i<=50);
                Return (0);
                }

Write to check input number is palindrome or not.
                Int main ()
{
                Int n , i , s=0, r;
                Printf(“enter any number “);
                Scant( “%d”, & n);
                N1 = n;
                Do
                {
                R = n % 10;
                N = n / 10;
                S = s*10 + r;
                If (s==n1)
Printf(“palindrome”);
Else
Printf(“nor palindrome”);
}
While (n!= 0);
Return(0);
}


No comments:

Post a Comment