1.8 Loop || For Loop || While Loop in java.
Loop (Repetition).
1. For Loop.
Syntax :
for(initialization; condition; inc/dec)
{
-
- //statement to be executed.
-
}
Initialization: is executed one time before the execution of the code block.
Condition : define the condition for executing the code block.
Inc/Dec : is executed every time after the code block has been executed.
Example :
for(int i=1; i<=5; i++) //increment
{
System.out.println("I Love Java StudyPoint");
}
for(int i=5; i>1; i--) //decrement
{
System.out.println("I Love Java StudyPoint");
}
While Loop: to be executed as specified condition is true.
Syntax :
while(condition)
{
- body of the the loop.
- statement to be executed.
}
// statement out side the loop (if condition condition will false).
example :
i = 0;
while(i<5)
{
System.out.println(i);
i++;
}
Example Program1 :
class Program1
{
public static void main(String args[])
{
for(int i=1; i<=5; i++)
{
System.out.println("I love Java StudyPoint");
}
}
}
Example Program2 :
class Program2
{
public static void main(String args[])
{
for(int i=5; i>1; i--)
{
System.out.println("I love Java StudyPoint");
}
}
}
Example Program3 :
class Program3
{
public static void main(String args[])
{
int i = 0;
while(i<5)
{
System.out.println(i);
i++;
}
}
}
for more details follow video give below:
Hii ....it have been helpful specially idea to start a blog which you read tha most you are good motivational speaker who brings solutions
ReplyDeleteGood.. it's helpful
ReplyDelete