Hey Guys,
Today we discussed about For Loop in Java.⇒ when we need repeat any condition multiple time then it is use.
⇒ it is top checker loop means first time it check condition, if condition is true then it'll print execution part of for loop Otherwise it terminates the loop.
⇒ we can make Pattern Program to use for loop.
⇒ it is top checker loop means first time it check condition, if condition is true then it'll print execution part of for loop Otherwise it terminates the loop.
⇒ we can make Pattern Program to use for loop.
Syntax of For Loop :-
for(initialization; condition ; increment/decrement) { statement(s); }
Flow of Execution of the for Loop
As a program executes, the interpreter always keeps track of which statement is about to be executed. We call this the control flow, or the flow of execution of the program.
Example1 ↬ For Loop
class ForLoopExample
{
public static void main(String args[])
{ for(int i=10; i>=1; i--)
{ System.out.println("The value of i is: "+i); } } }
Output :-
The value of i is: 10 The value of i is: 9 The value of i is: 8 The value of i is: 7 The value of i is: 6 The value of i is: 5 The value of i is: 4 The value of i is: 3 The value of i is: 2The value of i is: 1
Here:
int i=10 is initialization expression
i>1 is condition(Boolean expression)
i - - Decrement operation
0 Comments
Post a Comment