0
How to understand the loops?
Due to the fact that I'm becoming complicated studying the loops.
2 Answers
+ 3
Maybe the best way is to create your own codes for each loop.
Have each one print a number that increases with each loop iteration. See what the difference is.
+ 1
loop is for repeated activity, in real live i.e. if you search for something in a book. What you do:
Text whatISearch = "Loops in Java"
Page page
while( book.hasNextPage() ) {
page = book.nextPage()
if (page.contains( whatISearch) )
break //stop search
// else repeat it in next page
}
or
for( page = book.firstPage(); // start
page < book.endPage(); // "stop if not true"
page = book.nextPage() ) // "do before repeat"
{
if (page.contains( whatISearch) )
break //stop search
// else: "do before repeat"
// check: "stop if not true" condition
// repeat
}