for Loop:
- The
forloop is used when you know the number of iterations in advance. - It consists of an initialization statement, a condition for termination, and an update statement, all separated by semicolons.
while Loop:
-
- The
whileloop repeatedly executes a block of code as long as a given condition is true. - It checks the condition before each iteration.
- The
do-while Loop:
-
-
- The
do-whileloop is similar to thewhileloop, but it checks the condition after executing the block of code. This guarantees that the code block will be executed at least once.
- The
-
enhanced for Loop (for-each Loop):
-
-
-
- The enhanced
forloop is used to iterate over elements in an array or other iterable collections. - It simplifies the syntax for iterating over elements without needing explicit indexing.
- The enhanced
-
-
Shathana. S.R. Answered question September 7, 2023
