float [] pt1x = {0.580f, 0.680f, 0.780f};
float [] pt1y = {1.128f, 1.228f, 1.328f};
foreach (float xpt in pt1x) {
System.Console.WriteLine("xpt = " + xpt);
foreach (float ypt in pt1y) {
System.Console.WriteLine("ypt = " + ypt);
}
}
------my output:
xpt = 0.58
ypt = 1.128
ypt = 1.228
ypt = 1.328
xpt = 0.68
ypt = 1.128
ypt = 1.228
ypt = 1.328
xpt = 0.78
ypt = 1.128
ypt = 1.228
ypt = 1.328
---------------here is what I NEED
to get below:
xpt = 0.58
ypt = 1.128
xpt = 0.68
ypt = 1.228
xpt = 0.78
ypt = 1.328
float [] pt1x = {0.580f, 0.680f, 0.780f}; float [] pt1y = {1.128f, 1.228f, 1.328f};
Share
A nested loop isn’t what you want here. The inner loop is going to run in its entirety for each element of the outer loop.
If both your arrays have the same number of elements, just do one loop, and do all your operations on both arrays at the same time.