Java Loops
Loops:
Loops are repeating code, until a specific condition is met.
- While Loop
- DO-While Loop
- For Loop
- Continue and Break
While Loop :
int i=0;
While (condition ){
---//repeated until condition is true
Example
int i =0;
while(i<=4){
i++;
}
}
DO-while Loop :
Do - will excute first and checks its condition in while , if it is true , it is repeated ,once while becomes false it will come out of do while loop .
do
{
....
}while(condition);
example:
int j=1;
do {
//
j++
}while(j<=3);
For Loop :
for (intialization; condition; update statement){
---}
for (int i =0 ; i<=100; i++);
continue- skipping steps and loops.
break - is for stopping the loop .
Comments
Post a Comment