Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: For Statement

  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    For Statement

    Code:
    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.


    Code:
     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.
    Last edited by jpnv8; 03-30-2008 at 01:02 PM.

  • #2
    New to the CF scene
    Join Date
    Mar 2008
    Location
    Kentucky
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by kadams View Post
    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

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Code:
    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");
          		
             	}
              } 
          }
    1. x=0
    2. System.out.println(0+ "A");
      1. y=0
      2. System.out.println(0+ "B");
        1. z=0
        2. System.out.println(0+ "C");
        3. z=1
        4. System.out.println(1+ "C");
        5. z=2
        6. System.out.println(2+ "C");

      3. y=1
      4. System.out.println(1+ "B");
        1. z=0
        2. System.out.println(0+ "C");
        3. z=1
        4. System.out.println(1+ "C");
        5. z=2
        6. System.out.println(2+ "C");

        .............
    3. x=1
    4. System.out.println(1+ "A");
      ...............
    Lol, I learned some BBCode
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by abduraooft View Post
    Code:
    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");
          		
             	}
              } 
          }
    1. x=0
    2. System.out.println(0+ "A");
      1. y=0
      2. System.out.println(0+ "B");
        1. z=0
        2. System.out.println(0+ "C");
        3. z=1
        4. System.out.println(1+ "C");
        5. z=2
        6. System.out.println(2+ "C");

      3. y=1
      4. System.out.println(1+ "B");
        1. z=0
        2. System.out.println(0+ "C");
        3. z=1
        4. System.out.println(1+ "C");
        5. z=2
        6. System.out.println(2+ "C");

        .............
    3. x=1
    4. System.out.println(1+ "A");
      ...............
    Lol, I learned some BBCode
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •