1. Why doesn't this work?
I am trying to improve a program that prompts for values for a, b, c...l.=
=
I tried to use the input function, but that didn't work. So I returned t=
o
the basics. This is what I have.
clear_screen()
sequence prompt
atom prompt_loop
prompt =3D {97,98,99,100,101,102,103,104,105,106,107,108}
for prompt_loop =3D 1 to 12
print(1,prompt[prompt_loop])
end for
abort
it should print abcdefghijkl. No, that's wrong. It should print
979899100101102103104... but its not even doing that. It says I'm
redefining something. My logic seems OK. What's wrong?
--Alan
=
2. Re: Why doesn't this work?
Alan Tu wrote:
> I am trying to improve a program that prompts for values for a, b, c...l.
> I tried to use the input function, but that didn't work. So I returned to
> the basics. This is what I have.
>
> clear_screen()
> sequence prompt
> atom prompt_loop
> prompt = {97,98,99,100,101,102,103,104,105,106,107,108}
> for prompt_loop = 1 to 12
> print(1,prompt[prompt_loop])
> end for
> abort
>
> it should print abcdefghijkl. No, that's wrong. It should print
> 979899100101102103104... but its not even doing that. It says I'm
> redefining something. My logic seems OK. What's wrong?
>
> --Alan
Okay, I see what's wrong. pull out the "atom prompt_loop" and put a do after
the for line.
clear_screen()
sequence prompt
prompt = {97,98,99,100,101,102,103,104,105,106,107,108}
for a_loop = 1 to 12 do
print(1, prompt[a_loop])
end for
3. Re: Why doesn't this work?
Oh boy, I know it was something stupid like that missing "do". Thanks.
--Alan
=
4. Re: Why doesn't this work?
- Posted by Eduardo Uemura Okada <du at GENIUSNET.COM.BR>
May 27, 1998
-
Last edited May 28, 1998
>I am trying to improve a program that prompts for values for a, b, c...l.
>I tried to use the input function, but that didn't work. So I returned to
>the basics. This is what I have.
>clear_screen()
>sequence prompt
>atom prompt_loop
>prompt = {97,98,99,100,101,102,103,104,105,106,107,108}
>for prompt_loop = 1 to 12
>print(1,prompt[prompt_loop])
>end for
>abort
>it should print abcdefghijkl. No, that's wrong. It should print
>979899100101102103104... but its not even doing that. It says I'm
>redefining something. My logic seems OK. What's wrong?
>--Alan
Alan, you don't need to declare variables to a loop made with "for" loops,
the variable used in this routine will exist only during the loop, and using
for <variable>=<value> to <value> do , don't forget to add the do command at
end of statement, it's vital.
Just to finish, calling abort, don't forget the () ,I mean abort()
Following is your code , now running ok
clear_screen()
sequence prompt
--atom prompt_loop
prompt = {97,98,99,100,101,102,103,104,105,106,107,108}
for prompt_loop = 1 to 12 do
print(1,prompt[prompt_loop])
end for
abort()
See you later.
Eduardo Uemura Okada
du at geniusnet.com.br
PS - It's rare to me, as a beginner, answer a question in this mail list,
hope it helps
5. Re: Why doesn't this work?
HI Alan,
Some code for you may find helpful(or not):
--- code begins ---
sequence prompt,string
prompt={}
for x=97 to 108 do
prompt=prompt&x
end for
string="abcdefghijkl"
clear_screen()
puts(1,prompt)
puts(1,"\n")
print(1,prompt)
puts(1,"\n")
puts(1,string)
puts(1,"\n")
print(1,string)
puts(1,"\n")
puts(1,"abcdefghijkl")
puts(1,"\n")
print(1,"abcdefghijkl")
puts(1,"\n")
if compare(prompt,string)=0 then
puts(1,"\nprompt = string")
end if
--- code ends ---
Graeme
----------------------------------------------------
6. Re: Why doesn't this work?
At 07:03 PM 5/27/98 -0400, Alan Tu wrote:
>
>I am trying to improve a program that prompts for values for a, b, c...l.=
include input.e
constant prompt = {'a','b','c','d','e','f','g','h','i','j','k','l'}
sequence values
values = repeat(0,12)
clear_screen()
for i = 1 to length(prompt) do
values[i] = input("Enter a value for: " & prompt[i] &" \n")
end for
You do not declare a variable to use as a loop counter. This is
so common an operation that Euphoria does it automatically.
If you want to display characters, it's usually easier to
enter them as characters - don't mess around with numbers.
I try to make things that don't change (like the prompts)
into constants. They can't be accidently changed.
You want to store your values in a sequence, so you can do
maths on the whole thing with one command.
Regards,
Irv
7. Re: Why doesn't this work?
- Posted by Irv <irv at ELLIJAY.COM>
May 27, 1998
-
Last edited May 28, 1998
At 07:55 PM 5/27/98 -0400, I wrote:
>
1>include input.e
2>constant prompt = {'a','b','c','d','e','f','g','h','i','j','k','l'}
3>sequence values
4> values = repeat(0,12)
5>
6>clear_screen()
7>for i = 1 to length(prompt) do
8> values[i] = input("Enter a value for: " & prompt[i] &" \n")
9>end for
line 1 could be better written as:
constant prompt = "abcdefghijkl"
And it is a good idea to use length(prompt) rather than 12.
Suppose you later want to add "mnop"? You'd have to change
your loop code.
Irv
8. Re: Why doesn't this work?
- Posted by Alan Tu <ATU5713 at COMPUSERVE.COM>
May 27, 1998
-
Last edited May 28, 1998
Thanks for the reply, Irv. Good tip regarding the constants.
--Alan
=