C#-Loops
Loop:- When you need to executed a block of code several numbers of time,the statement are executed sequentially. The first statement in a function is executed first,followed by the second and so on.
A Loop statement is allow us to execute a statement or a group of statement multiple times.
Types of Loops:-
1.while-loop:-It repeats the statement or a group of statement while a giving condition is true.It tests the condition before executing the loop body.It consists of a test expression.If the test expression is evaluated to true,then statement inside the while loop are executed.If False,then it terminate.
2.Do while loop:-In the do while loops condition is checked after the body is executed.The body of do while loop is executed first,then the test expression is evaluated.If it is true the body of loop is executed.When test expression false,loop terminated.
3.for-loop:-It has three statements(initialization,condition and iterator). The initialization statement is executed at first.Here,the variable initialize.Then the condition is evaluated. If the condition is true,the statement inside the loop is executed. Then,the iterator statement is executed which usually change the value of initialized variable. Again the condition evaluated.The process continues until the condition evaluated is False.If it is false,the loop terminate.




Comments
Post a Comment