Java for loops is very similar to Java while loops in that it continues to process a block of code until a statement becomes false, and everything is defined in a single line.
Syntax:
for ( init; condition; increment )
{
statement(s);
}
Java Tutorial, Java Study, Learn Java, Java Lab@home, Java Cycle test, Java Projects, Java Assignments, Java Notes and much more..
for ( init; condition; increment )
{
statement(s);
}
do
{
statement(s);
}while( condition );
While (condition)
{
statement(s);
Incrementation;
}
switch(variable)
{
case 1:
//execute your code
break;
case n:
//execute your code
break;
default:
//execute your code
break;
}
if(condition)
{
//execute your code
}
else if(condition n)
{
//execute your code
}
else
{
//execute your code
}
if(condition)
{
//execute your code
}
else
{
//execute your code
}
if(condition)
{
statement 1;
statement 2;
...
}
1
2
3
4
5
6
7
8
9
10
| import javax.swing.JApplet; import java.awt.Graphics; public class MyFirstApplet extends JApplet { public void paint(Graphics g) { g.drawString( "Hello, Java-Buddy!" , 50 , 50 ); } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| public class InsertionSort { public static void main(String[] args) { System.out.println( "Hello, Java-Buddy!" ); MyData myData = new MyData(); myData.show(); //Before sort myData.InsertionSort(); myData.show(); //After sort } |