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:

Codecademy Code Foundations

Popular Posts

Categories

Android (23) AngularJS (1) Assembly Language (2) Books (10) C (75) C# (12) C++ (81) Course (1) Data Strucures (4) Downloads (1) Engineering (13) flutter (1) FPL (17) Hadoop (1) HTML&CSS (38) IS (25) Java (87) Leet Code (4) Pandas (1) PHP (20) Projects (17) Python (264) R (69) Selenium Webdriver (2) Software (14) SQL (27)