![]() ![]() The while loop : This executes a statement for an unknown number of times The for loop : This executes a statement for a particular number of times What are the various types of Loops in Java? In Java we have three types of basic loops: for, while, and do-while. Loops in Java:Īs explained above - Loops are used to execute a set of statements repeatedly until a particular condition is satisfied. Loops are specifically designed to perform repetitive tasks with one set of code. This is where loops come into the picture. Computers are now very smart and meant to reduce the task, although the computer would not mind executing your 1000 lines but still it wants you to play smart on that. ![]() Coding 1000 lines to do this would be mundane and stupidity. For example, imagine you have to write a program that performs a repetitive task such as printing 1 to 1000. There can be a situation where you need to execute a block of code again and again for a specific number of times.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |