Title | Loop |
---|---|
Author | Jahnavi g n |
Course | BCA |
Institution | University of Mysore |
Pages | 18 |
File Size | 488.3 KB |
File Type | |
Total Downloads | 4 |
Total Views | 128 |
HELO...
Loopsi nJav a In programming languages, loops are used to execute a set of instructions/functions repeatedly when some conditions become true. There are three types of loops in java. o
for loop
o
while loop
o
do-while loop
1
J av aForLoopv sWhi l eLoopv sDoWhi l eLoop
Comparison Introduction
for loop
while loop
do while loop
The Java for loop is a control flow
The Java while loop is a
The Java do while loop is
statement that iterates a part of
control flow statement
a control flow statement
the programs multiple times.
that executes a part of
that executes a part of
the programs repeatedly
the programs at least
on the basis of given
once and the further
boolean condition.
execution depends upon the given boolean condition.
When to
If the number of iteration is fixed,
If the number of iteration
If the number of iteration
use
it is recommended to use for loop.
is not fixed, it is
is not fixed and you must
recommended to use
have to execute the loop
while loop.
at least once, it is recommended to use the do-while loop.
Syntax
Example
for(init;condition;incr/decr){
while(condition){
do{
// code to be executed
//code to be executed
//code to be executed
}
}
}while(condition);
//for loop
//while loop
//do-while loop
for(int i=1;i...