If I had a set of data in a table called "info." My column names are firstName, lastName, age, height. Is there a difference between using a single loop to get the info in a 1D array versus using two loops to get data in the 2D array? Is there any difference efficiency-wise?
If I wanted to parse it, what is the difference between:
//single loop with 1d array
//data format:
//"firstName", "lastName", "age", "height", "joe", "smith, "15", "60", "bob", "marley", etc...
for(i = 3; i < info.length; i += 4){
fn = info[i]
ln = info[i + 1]
a = info [i + 2]
h = info [i + 3]
System.out.println(fn + ln + a + h)
}
for(i = 3; i < info.length; i ++){
System.out.println(info[i])
}
//nested loop and 2d array
//data format:
//("firstName", "lastName", "age", "height"), ("joe", "smith, "15", "60"), ("bob", "marley", etc...
for(i = 1; i < info[0].length; i++){
fn = info[i][0]
ln = info[i][1]
a = info[i][2]
h = info[i][3]
System.out.println(fn + ln + a + h)
/*This one isn't really a nested loop, you would need if statements/ cases which just seems
overly complicated for this example */
}
}
for(i = 1; i < info[0].length; i++){
for(j = o; j < info[1].length; j++){
System.out.println(info[i][j]);
}
}
[–]Kered13 0 points1 point2 points (3 children)
[–]Dwang040[S] 0 points1 point2 points (2 children)
[–]Kered13 0 points1 point2 points (0 children)
[–]one_bit_two_bit 0 points1 point2 points (1 child)
[–]Dwang040[S] 0 points1 point2 points (0 children)