...

View Full Version : For Statement



jpnv8
03-29-2008, 04:10 AM
import java.io.*;

public class For

{
public static void main (String [] args)


{
int x;

for(x=0;x<3;x++) {

System.out.println(x);

/*
----------------------------------------------------
the SEQUENCE the computer reads the FOR statement
----------------------------------------------------
1.x=0
2.x<3
3.System.out.println(x);
4.x++
5.x<3
6.System.out.println(x);
7.x++
8.x<3
9.System.out.println(x);
10.x++
11.x<3
12.EXIT

-------
OUTPUT
-------
0
1
2

*/

}
}
}

A.)
I know how a single for statement works (see above) a help for those who doesnt know single FOR statement for newbies like me

Now Im confused in how three nested FOR statement works. Can you please show me the sequence of a 3 nested IF statement.



int x,y,z;

for(x=0;x<2;x++) {
System.out.println(x+ "A");
for(y=0;y<2;y++) {
System.out.println(y+ "B");
for(y=0;y<2;y++) {
System.out.println(y+ "C");

}
}
}

hey thx in advance.

kadams
03-30-2008, 05:29 AM
I'm confused. You're asking about showing how three nested If statements would work, but your code shows three "for" loops. Which are you looking for, nested If's, or nested For loops?

jpnv8
03-30-2008, 01:09 PM
I'm confused. You're asking about showing how three nested If statements would work, but your code shows three "for" loops. Which are you looking for, nested If's, or nested For loops?

Sorry bro i mistyped the nested If statements.

It should have been nested 3 FOR statement

I edited the first post thanks kadams

abduraooft
03-30-2008, 01:21 PM
for(x=0;x<2;x++) {
System.out.println(x+ "A");
for(y=0;y<2;y++) {
System.out.println(y+ "B");
for(z=0;z<2;z++) {
System.out.println(z+ "C");

}
}
}

x=0
System.out.println(0+ "A");

y=0
System.out.println(0+ "B");

z=0
System.out.println(0+ "C");
z=1
System.out.println(1+ "C");
z=2
System.out.println(2+ "C");


y=1
System.out.println(1+ "B");

z=0
System.out.println(0+ "C");
z=1
System.out.println(1+ "C");
z=2
System.out.println(2+ "C");

.............

x=1
System.out.println(1+ "A");
...............
Lol, I learned some BBCode :D

jpnv8
04-02-2008, 09:54 AM
for(x=0;x<2;x++) {
System.out.println(x+ "A");
for(y=0;y<2;y++) {
System.out.println(y+ "B");
for(z=0;z<2;z++) {
System.out.println(z+ "C");

}
}
}

x=0
System.out.println(0+ "A");

y=0
System.out.println(0+ "B");

z=0
System.out.println(0+ "C");
z=1
System.out.println(1+ "C");
z=2
System.out.println(2+ "C");


y=1
System.out.println(1+ "B");

z=0
System.out.println(0+ "C");
z=1
System.out.println(1+ "C");
z=2
System.out.println(2+ "C");

.............

x=1
System.out.println(1+ "A");
...............
Lol, I learned some BBCode :D
Hey thanks for the answer.. but Im still confused..


Can you please or someone arrange the SEQUENCE the computer reads the FOR statement. The previous answer was hopping statements like (x>2) or (z++). Im confused.. thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum