1

I have written a program which generates parameter index for 2 variables. Say, a and b in steps of 5. like this I have to do for 23 variables. So I don't want to write 23 for-loops to run, how can I make it into a single for-loop which is common for all 23 variables. I hope it can be done with an array, but i don't know how to implement it via program. Could you please help me?

Program:

int z, p
float a, b
float  a0, an, s, a1, b0, bn, b1
str var
s=5; a0=1; an=10; b0=8; bn=13     // s= steps, a0, b0= initial  value, an,bn=final value
z=0

a1=(an-a0)/s
b1=(bn-b0)/s

for (a=(a1+a0);a<=an;a=a+a1)   
for (b=(b1+b0);b<=bn;b=b+b1)
echo {z} {a} {b}  -format "%25s" >> /home/genesis/genesis-2.3/genesis/Scripts/kinetikit/dhanu19.txt
z=z+1
end
end

output : dhanu19.txt
                        0                      2.8                        9
                        1                      2.8                       10
                        2                      2.8                       11
                        3                      2.8                       12
                        4                      2.8                       13
                        5                      4.6                        9
                        6                      4.6                       10
                        7                      4.6                       11
                        8                      4.6                       12
                        9                      4.6                       13
                       10                      6.4                        9
                       11                      6.4                       10
                       12                      6.4                       11
                       13                      6.4                       12
                       14                      6.4                       13
                       15                      8.2                        9
                       16                      8.2                       10
                       17                      8.2                       11
                       18                      8.2                       12
                       19                      8.2                       13
                       20                       10                        9
                       21                       10                       10
                       22                       10                       11
                       23                       10                       12
                       24                       10                       13
3
  • Homework means he does something he wants to learn, so, if you don't have a good answer, why would you leave a stupid answer like that? Commented Jan 28, 2009 at 10:07
  • Maybe if you wrote that again, this time in English or something resembling it enough, someone may help you with your homework Commented Jan 28, 2009 at 10:08
  • I'm not saying that he should't post homework questions, but that it should be tagged appropriately, if its homework and he's trying to learn, theres no point just feeding him the answers Commented Jan 28, 2009 at 10:13

3 Answers 3

3

Have you considered writing either a script or a program to write the script for you? Generating shell-scripts, then running them can sometimes be a powerful solution to problems.

Sign up to request clarification or add additional context in comments.

Comments

0

Which Shell are you referring to? Declaring Arrays has some syntactical differences between zsh, bash or so...

Comments

0

Let's assume you write the 23 for loop. If you have 5 steps for each loop, you will end up with 5^23 parameter !

Let's suppose each loop outputs 1 byte, you still need to store something like 10^16 bytes, or ten thousand terabytes. I think you should reconsider your problem, or reformulate your question

Edit : This is not a forums (and aven in forums you can edit your post). Please edit your question instead of posting new answer, I think it is interesting

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.