Hi
i want to get a user to input x which then creates an nested loop with x
levels. each level of the loop has the same number of iterations e.g.
for the case where x=3, the following code is executed
int [] i=new int[x-1];
for (i[2]=0;i[2]<limit;i[2]++)
{
for (i[1]=0;i[1]<limit;i[1]++)
{
for (i[0]=0;i[0]<limit;i[0]++)
{
newLowTotal=Sum(i[0],i[1],i[2]);
}
}
}
for the case where x=4, the above would be wrapped by
for (i[3]=0;i[3]<limit;i[3]++)
{
.......
newLowTotal=Sum(i[1],i[2],i[3],i[4]);
.......
}
and notice the Sum array changes as well!
My initial thoughts are an arraylist might solve the varied size of Sum
array and iteration rather than for-looping might solve varied looping
size. But I can't really work out how. Anyone got any ideas? 2 1575
tony collier <me*****@hotmail.com> wrote in
news:Xn*************************@140.99.99.130: Hi
i want to get a user to input x which then creates an nested loop with x levels. each level of the loop has the same number of iterations e.g.
for the case where x=3, the following code is executed
int [] i=new int[x-1];
for (i[2]=0;i[2]<limit;i[2]++) { for (i[1]=0;i[1]<limit;i[1]++) { for (i[0]=0;i[0]<limit;i[0]++) {
newLowTotal=Sum(i[0],i[1],i[2]); } } } for the case where x=4, the above would be wrapped by
for (i[3]=0;i[3]<limit;i[3]++) {
...... newLowTotal=Sum(i[1],i[2],i[3],i[4]);
...... } and notice the Sum array changes as well!
My initial thoughts are an arraylist might solve the varied size of Sum array and iteration rather than for-looping might solve varied looping size. But I can't really work out how. Anyone got any ideas?
sorry - the 2nd newLowTotal statement should read:
newLowTotal=Sum(i[0],i[1],i[2],i[3]);
tony collier <me*****@hotmail.com> wrote in
news:Xn************************@140.99.99.130: tony collier <me*****@hotmail.com> wrote in news:Xn*************************@140.99.99.130:
Hi
i want to get a user to input x which then creates an nested loop with x levels. each level of the loop has the same number of iterations e.g.
for the case where x=3, the following code is executed
int [] i=new int[x-1];
for (i[2]=0;i[2]<limit;i[2]++) { for (i[1]=0;i[1]<limit;i[1]++) { for (i[0]=0;i[0]<limit;i[0]++) {
newLowTotal=Sum(i[0],i[1],i[2]); } } } for the case where x=4, the above would be wrapped by
for (i[3]=0;i[3]<limit;i[3]++) {
...... newLowTotal=Sum(i[1],i[2],i[3],i[4]);
...... } and notice the Sum array changes as well!
My initial thoughts are an arraylist might solve the varied size of Sum array and iteration rather than for-looping might solve varied looping size. But I can't really work out how. Anyone got any ideas?
sorry - the 2nd newLowTotal statement should read:
newLowTotal=Sum(i[0],i[1],i[2],i[3]);
I must drink coffee - i meant recursive function , not iteration This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: chad |
last post by:
I am writing a program to do some reliability calculations that
require several nested for-loops. However, I believe that as the
models become more complex, the number of required for-loops will...
|
by: mark |
last post by:
My problem is I need to have a "nested" repeater. I have an array which I
load into a hashtable - that part works great. I can setup the second
repeater to work just fine, as long as it's not...
|
by: Martin Schou |
last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C,
which explains why I'm doing an exercise like this.
In the following tripple nested loop:
int digit1 = 1;
int digit2 = 0;...
|
by: Neptune |
last post by:
Hello.
I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)"
(Sam's series), and for nested loops, he writes (p116) "It's often
necessary to create a loop even when you are...
|
by: Peter Olcott |
last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html
Why is C# 500% slower than C++ on Nested Loops ???
Will this problem be solved in...
|
by: Javaman59 |
last post by:
Using local declarations within a block often makes code more readable, but
is it less efficient? eg...
void P() {
while (...) {
int i = ...;
bool b = ...;
....
}
}
|
by: Peter Olcott |
last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html
The above link shows that C# is 450% slower on something as simple as a nested
loop....
|
by: =?Utf-8?B?QUEyZTcyRQ==?= |
last post by:
Could someone give me a simple example of nested scope in C#, please?
I've searched Google for this but have not come up with anything that makes
it clear. I am looking at the ECMA guide and...
|
by: Nathan Sokalski |
last post by:
I have several nested For loops, as follows:
For a As Integer = 0 To 255
For b As Integer = 0 To 255
For c As Integer = 0 To 255
If <Boolean ExpressionThen <My CodeElse Exit For
Next
If Not...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |