www.webdeveloper.com
Results 1 to 4 of 4

Thread: Conditional For Loop

Hybrid View

  1. #1
    Join Date
    Aug 2013
    Posts
    2

    Conditional For Loop

    What would be the best way to make this a conditional for loop.

    var type_of_loop_single = 1
    // var type_of_loop_double = 2

    var rows = grid.get_rows();
    for (var i = 0; i < rows.get_length() ; i++) {
    var row = rows.get_row(i);
    for (var j = 0; j < row.get_cellCount() ; j++) {
    var cell = row.get_cell(j);
    }
    }

    If the type of loop is 1, then I do want to use the i and j variables to loop through. If the type of loop is 2, then I want the i variable to work the same way, but I will name the j variable like this:
    var cell = row.get_cellByColumnKey(myColumnName)

    What would be a good way to structure this?

  2. #2
    Join Date
    Jun 2008
    Posts
    106
    You confused me. Can you explain what you are trying to accomplish?

  3. #3
    Join Date
    Aug 2013
    Posts
    2
    Quote Originally Posted by tenfold View Post
    You confused me. Can you explain what you are trying to accomplish?
    I don't know what else to say. I explained it. Switch between the type of loop to determine if it should do just one loop or two.

  4. #4
    Join Date
    Feb 2012
    Location
    Tallahassee, FL
    Posts
    280
    Quote Originally Posted by tenfold View Post
    You confused me. Can you explain what you are trying to accomplish?
    Same with me, but I think this may be what you want:

    Code:
    var type_of_loop_single = 1;
            // var type_of_loop_double = 2
    
            var rows = grid.get_rows();
            for (var i = 0; i < rows.get_length() ; i++) {
                var row = rows.get_row(i);
                if(type_of_loop_single == 1){
                    for (var j = 0; j < row.get_cellCount() ; j++) {
                        var cell = row.get_cell(j);
                    }
                }else{
                    var cell = row.get_cellByColumnKey(myColumnName);
                }
    
            }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles