1. Length

------=_NextPart_000_000E_01C01812.96AA6040
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I was wondering if there's a way to use length in a loop:

object desc
puts(1,"Enter a number from 1-9)
desc=3Dwait_key()
for length(desc) do                -- if desc is 9 then puts 0 nine =
times.
puts(1,"0")
end for

Also, is there a way to eliminate the enter key number stored in any =
gets(0) vairable?

-Thanks
-Thomas

------=_NextPart_000_000E_01C01812.96AA6040
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I was wondering if there's a way to use =
length in a=20
loop:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>object desc</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>puts(1,"Enter a number from =
1-9)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>desc=3Dwait_key()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>for length(desc) do&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- if desc is 9 =
then=20
puts 0 nine times.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>puts(1,"0")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>end for</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Also, is there a way to eliminate the =
enter key=20
number stored in any gets(0) vairable?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-Thanks</FONT></DIV>

------=_NextPart_000_000E_01C01812.96AA6040--

new topic     » topic index » view message » categorize

2. Re: Length

------=_NextPart_000_000D_01C0182F.E5F45B20
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Hi Thomas
Try this:

object desc
puts(1,"Enter a number from 1-9)
desc=3Dwait_key()
for i =3D 1 to length(desc) do                -- if desc is 9 then puts =
0 nine times.
puts(1,"0")
end for
  ----- Original Message -----=20
  From: Paul Kerslake=20
  To: EUPHORIA at LISTSERV.MUOHIO.EDU=20
  Sent: Wednesday, September 06, 2000 2:56 PM
  Subject: Length


  I was wondering if there's a way to use length in a loop:

  object desc
  puts(1,"Enter a number from 1-9)
  desc=3Dwait_key()
  for length(desc) do                -- if desc is 9 then puts 0 nine =
times.
  puts(1,"0")
  end for

  Also, is there a way to eliminate the enter key number stored in any =
gets(0) vairable?

  -Thanks
  -Thomas

------=_NextPart_000_000D_01C0182F.E5F45B20
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Hi Thomas</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Try this:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>object desc</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>puts(1,"Enter a number from =
1-9)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>desc=3Dwait_key()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>for i =3D 1 to length(desc) =
do&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- if desc is 9 =
then=20
puts 0 nine times.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>puts(1,"0")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>end for</FONT></DIV></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dpaulk at UNISERVE.COM href=3D"mailto:paulk at UNISERVE.COM">Paul =
Kerslake</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3DEUPHORIA at LISTSERV.MUOHIO.EDU=20
  =
</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, September 06, =
2000 2:56=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Length</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>I was wondering if there's a way to =
use length in=20
  a loop:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>object desc</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>puts(1,"Enter a number from =
1-9)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>desc=3Dwait_key()</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>for length(desc) do&nbsp;&nbsp;&nbsp; =

  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- if desc is =
9 then=20
  puts 0 nine times.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>puts(1,"0")</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>end for</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Also, is there a way to eliminate the =
enter key=20
  number stored in any gets(0) vairable?</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>-Thanks</FONT></DIV>
  <DIV><FONT face=3DArial =

------=_NextPart_000_000D_01C0182F.E5F45B20--

new topic     » goto parent     » topic index » view message » categorize

3. Re: Length

------=_NextPart_000_0058_01C01884.623712A0
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Thomas,

I can understand the problems you have in learning Euphoria, since I =
remember having about the same ones, when I first tried writing my own =
programs (In a previous age, that was)
However, you make some semantic errors!
1) When you type a '9' you see a character 9 on your screen. But the =
internal code for this character is 57. You can see this by executing =
the statement: ? '9'
A way to 'translate' it into a number is subtracting 49, being the value =
of '0'.
desc -=3D '0'
2) The program cannot determine the length of an 'atom', only sequences =
have lengths. You do not need the length() function here. Instead you =
should use:
for i =3D 1 to desc do
    puts(1, '0')
end for

Your second question: gets(0) reads from the keyboard. You type '9' and =
then ENTER. If you should use ? desc now, you would get {57,10}.
These are the internal values for the keys you pressed. To extract only =
the number key, use:
desc =3D desc[1]

So, your program could look like this:

object desc
puts(1,"Enter a number from 1-9 ")    -- neater to have a space before =
input
desc =3D gets(0)                                    -- lowlevel I/O, C =
programmers call this
desc =3D desc[1]
desc -=3D '0'
for i =3D 1 to desc do
    puts(1, '0')
end for

To have extra line feeds in your output, use puts(1, '\n') between some =
of these lines.

Hope this helps,    Ad
  ----- Oorspronkelijk bericht -----=20
  Van: Paul Kerslake=20
  Aan: EUPHORIA at LISTSERV.MUOHIO.EDU=20
  Verzonden: woensdag 6 september 2000 23:56
  Onderwerp: Length


  I was wondering if there's a way to use length in a loop:

  object desc
  puts(1,"Enter a number from 1-9)
  desc=3Dwait_key()
  for length(desc) do                -- if desc is 9 then puts 0 nine =
times.
  puts(1,"0")
  end for

  Also, is there a way to eliminate the enter key number stored in any =
gets(0) vairable?

  -Thanks
  -Thomas

------=_NextPart_000_0058_01C01884.623712A0
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>Hi Thomas,</DIV>
<DIV>&nbsp;</DIV>
<DIV>I can understand the problems you have in learning Euphoria, since =
I=20
remember having about the same ones, when I first tried writing my own =
programs=20
(In a previous age, that was)</DIV>
<DIV>However, you make some semantic errors!</DIV>
<DIV>1) When you type a '9' you see a character 9 on your screen. But =
the=20
internal code for this character is 57. You can see this by executing =
the=20
statement: <STRONG>? '9'</STRONG></DIV>
<DIV>A&nbsp;way to 'translate' it into a&nbsp;number is subtracting 49, =
being=20
the value of '0'.</DIV>
<DIV><STRONG>desc -=3D '0'</STRONG></DIV>
<DIV>2) The program cannot determine the length of an 'atom', only =
sequences=20
have lengths.&nbsp;You do not need the length() function here. Instead =
you=20
should use:</DIV>
<DIV><STRONG>for i =3D 1 to desc do</STRONG></DIV>
<DIV><STRONG>&nbsp;&nbsp;&nbsp; puts(1, '0')</STRONG></DIV>
<DIV><STRONG>end for</STRONG></DIV>
<DIV>&nbsp;</DIV>
<DIV>Your second question: gets(0) reads from the keyboard. You type '9' =
and=20
then ENTER. If you should use <STRONG>? desc </STRONG>now, you would get =

{57,10}.</DIV>
<DIV>These are the internal values for the keys you pressed. To extract =
only the=20
number key, use:</DIV>
<DIV><STRONG>desc =3D desc[1]</STRONG></DIV>
<DIV>&nbsp;</DIV>
<DIV>So, your program could look like this:</DIV>
<DIV>&nbsp;</DIV>
<DIV><STRONG>object desc</STRONG></DIV>
<DIV><STRONG>puts(1,"Enter a number from 1-9 ")&nbsp;&nbsp;&nbsp; -- =
neater to=20
have a space before input</STRONG></DIV>
<DIV><STRONG>desc =3D gets(0)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- lowlevel =
I/O, C=20
programmers call this</STRONG></DIV>
<DIV><STRONG>desc =3D desc[1]</STRONG></DIV>
<DIV><STRONG>desc -=3D '0'</STRONG></DIV>
<DIV><STRONG>for i =3D 1 to desc do</STRONG></DIV>
<DIV><STRONG>&nbsp;&nbsp;&nbsp; puts(1, '0')</STRONG></DIV>
<DIV><STRONG>end for</STRONG></DIV>
<DIV>&nbsp;</DIV>
<DIV>To have extra line feeds in your output, use puts(1, '\n') between =
some of=20
these lines.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Hope this helps,&nbsp;&nbsp;&nbsp; Ad</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Oorspronkelijk bericht ----- =
</DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>Van:</B>=20
  <A href=3D"mailto:paulk at UNISERVE.COM" title=3Dpaulk at UNISERVE.COM>Paul =
Kerslake</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Aan:</B> <A=20
  href=3D"mailto:EUPHORIA at LISTSERV.MUOHIO.EDU"=20
  title=3DEUPHORIA at LISTSERV.MUOHIO.EDU>EUPHORIA at LISTSERV.MUOHIO.EDU</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Verzonden:</B> woensdag 6 september =
2000=20
  23:56</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Onderwerp:</B> Length</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>I was wondering if there's a way to =
use length in=20
  a loop:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>object desc</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>puts(1,"Enter a number from =
1-9)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>desc=3Dwait_key()</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>for length(desc) do&nbsp;&nbsp;&nbsp; =

  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- if desc is =
9 then=20
  puts 0 nine times.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>puts(1,"0")</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>end for</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Also, is there a way to eliminate the =
enter key=20
  number stored in any gets(0) vairable?</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>-Thanks</FONT></DIV>
  <DIV><FONT face=3DArial =

------=_NextPart_000_0058_01C01884.623712A0--

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu