Posts Tagged looping
Java Tutorial 10 – Enhanced For Loops
enhanced for loops are very useful for arrays.
to loop through array what we generally do is we take one int as index and use this index inside loop to point to array location and then we increment it.
But there is one more easiest way to loop through array which is called Enhanced For Loop. it automatically increments index and stops at the end of the array. let me show you one example:
For loop:
Java Tutorial 4 – Looping
I think you guys can do following:
- create new class
- now add following lines in main method
no need to import anything because we are not using scanner here.
Syntax:
while ( condition ) {
….to do …
}
it will first check the condition and if condition is true it run the code within the {} and again check the condition, this will continue till condition will not become false. Once it become false loop is ended.
we created here an int i and printed 1 line each time it loops.
and If u know C/C++ its going to boring for you ! because its same.
Again Doubts and suggestions are invited.
Peace.
