C Programming looping statements (part 2)
Next looping statements will continue here
2.while:
While is one of the important looping statement
In while, we assign at somewhere ,condition we place in while and increment or decrement at last. While and for is same but the difference is syntax functionality is same.
By using while code length is increasing.
Syntax:
Assignment;
While (condition)
//Simple statements;
Increment or decrement operation;
While loop is simple like for loop but writing code is somewhat difficulty in means of writing three statements in a code.
Example----
i=0;
while(i<5)
printf ("SSCprogramming");
i++;
In the above code assignment is happened initially. After that while checks the condition then it moves on next statements inside the while loop
Then increment happen.
Output is 5 times prints SSCprogramming
3. Do-while
This is reverse of while in case of checking condition.
In this intialisation or assignment will be at some place before the condition checking.
After that do the some statements. And then checks the condition..
Syntax:
Assignment
Do
Simple statements
While (condition)
In this assignment is for assign. And then do the what operations in the do loop and then checks the condition.
Example----
i=0;
do{
printf("SSCprogramming");
}while (i<5)
i++;
Explanation:
i=0; is for assignment
do is for do the next statement
While for condition checking and making iteration
i++; for increment...
Output will be 6 times SSCprogramming
Note: while print zero times if the condition is false at intially, In case of
Do-while will print one time if the condition is false also.
That means while check the condition first
But in case of do-while checks the condition after performing the operation of executing the statement
These are looping statements....
We have switch() case we can study in next post
Comments
Post a Comment