Monday, 9 April 2018

Loop Structure

  While Loop

 Here, we will explain a while loop , How to work a while loop.

Syntax:-
While(condition)
{
statement()
}


Example:-
public class MyClass
{
public static void main(string[] arg)
{
int a=0;
while(a<10)
{
System.out println(“Output=”a);
a++;
}
}
}

do while loop (Java)

  • Here we will explain a do while loop.
Syntax:-
do
{
statement()
}
while(Condition)
 }

Example:-
public class Myclass
{
public static void main(string[] arg)
{
int b=0;
do
{
System.out.println(b);
b++;
}
while(b<=10);
}
}

How to use “For” loop in Java

  • The For loop is same as while and do while.
Syntax:-
For(/* init ; expression ; increment */)
{
}

Example:-
public class MyCalss
{
public static void main(string[] arg)
{
int[] myintarray={100,31,26,48,52}
for(int index=0;index<5;index++)
{
System.out.println([index]);
}
}
}
New format to declare a for loop.
for(int element : myintarray)
{
System.out.println(element);
}

1 comment:

Popular Posts

Categories

Android (21) AngularJS (1) Books (3) C (75) C++ (81) Data Strucures (4) Engineering (13) FPL (17) HTML&CSS (38) IS (25) Java (85) PHP (20) Python (83) R (68) Selenium Webdriver (2) Software (13) SQL (27)