For loop
public class Jbt_Forloop
{
public static void
main(String[] args)
{
System.out.println("For
Loop");
int i;
for(i=0; i<5 i="" span="">5>
{
System.out.println("Current
Value of i "+i);
System.out.println("Termination
conditions value is :"+(i<5 span="">5>
}
System.out.println("Outside
of loop");
System.out.println("Termination
conditions value is :"+(i<5 span="">5>
}
}
Syntax of Enhance for loop
public class Jbt_Forloop
{
public static void
main(String[] args)
{
System.out.println("Enhanced
For loop");
int[] intArr =
{1,2,3,4,5};
for(int j: intArr)
{
System.out.println(j);
}
System.out.println("-------------------------------------");
for(Object j: intArr)
{
System.out.println(j);
}
}
}
Code While loop
class Jbt_Whileloop
{
public static void
main(String[] args)
{
System.out.println("While
For Loop Example");
boolean bool = true;
while (bool)
{
System.out.println("Expression
value is True");
bool = false;
}
System.out.println("Expression
value is False now");
}
}
Do-While Loop
class Jbt_Dowhileloop
{
public static void
main(String[] args)
{
int i=0;
do
{
System.out.println("Inside
Do-while loop");
System.out.println("Value
of expression is :"+(i<5 span="">5>
i++;
}
while (i<5 span="">5>
System.out.println("Outside
of Do-while loop");
System.out.println("Value
of expression is :"+(i<5 span="">5>
}
}
No comments:
Post a Comment