





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This fille shows you iterative constructs in java. Very easy to understand iteration
Typology: Summaries
1 / 37
This page cannot be seen from the preview
Don't miss anything!






























Definition
Entry controlled Loop While loop and “for” loop are called as entry- controlled loop, since they check the condition in the beginning of the loop itself.
Exit controlled Loop Do… while loop is called as exit-controlled loop, since it checks the condition at the end of the loop. .
For loop
How for loop works?
We can initialize the variable, check condition and increment/decrement value. It consists of four parts: Initialization Condition^ Statement Incr/decr It is the initial condition which is executed once when the loop starts. Here, we can initialize the variable, or we can use an already initialized variable. It is an optional condition. It is the second condition which is executed each time to test the condition of the loop. It continues execution until the condition is false. It must return boolean value either true or false. It is an optional condition. The statement of the loop is executed each time until the second condition is false It increments or decrements the variable value. It is an optional
Examples of for loop To print first 10 natural numbers 1 2 3 4 5 6 7 8 9 10 initialization test expression incr/decr for(int I = 1;i<=10;i++) { System.out.println(i); }
While Loop The syntax of while loop is while (testExpression) { // codes inside body of while loop }
Flowchart
Example int x=1; while (x<=10) { System.out.println (x); x++; } Note: If there is more than one statement in the loop body, then it is compulsory to group them within a pair of curly block { } initialization test expression incr/decr