/    Sign up×
Community /Pin to ProfileBookmark

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?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@tenfoldAug 02.2013 — You confused me. Can you explain what you are trying to accomplish?
Copy linkTweet thisAlerts:
@derekmhartauthorAug 02.2013 — You confused me. Can you explain what you are trying to accomplish?[/QUOTE]

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.
Copy linkTweet thisAlerts:
@NoEffinWayAug 02.2013 — You confused me. Can you explain what you are trying to accomplish?[/QUOTE]

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);
}

}
[/CODE]
×

Success!

Help @derekmhart spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...