Board index » delphi » question: repeat/until
u246063...@spawnkill.ip-mobilphone.net (y_jim542...@yahoo.com)
Delphi Developer |
Sun, 08 Aug 2004 06:45:08 GMT
|
u246063...@spawnkill.ip-mobilphone.net (y_jim542...@yahoo.com)
Delphi Developer |
Sun, 08 Aug 2004 06:45:08 GMT
question: repeat/until
HI,
does i ever become equal to 10?. if not, how can i make it equal to 10?. J j := 0; -- |
Femme Verbee
Delphi Developer |
Sun, 08 Aug 2004 07:52:38 GMT
Re:question: repeat/until"y_jim542...@yahoo.com" <u246063...@spawnkill.ip-mobilphone.net> schreef Quote> HI, stupid questions here. You would have found out that your program does not compile, because you are trying to assign. And you would have found the answer to your question yourself if you did manage to get it running. Would you please stop posting to the non existent group |
Eric Smit
Delphi Developer |
Sun, 08 Aug 2004 09:08:53 GMT
Re:question: repeat/untilQuoteu246063...@spawnkill.ip-mobilphone.net (y_jim542...@yahoo.com) writes: Quote> if not, how can i make i := 10; -- GOD is real unless declared integer. |
Virgi
Delphi Developer |
Sun, 08 Aug 2004 10:33:58 GMT
Re:question: repeat/untilIn article <l.1014158708.1680084228@[63.127.215.130]>, u246063...@spawnkill.ip-mobilphone.net (y_jim542...@yahoo.com) Quotewrote: If j is of type integer, " j := j + 0.5" may not change the value of |
John Blackwoo
Delphi Developer |
Sat, 28 Aug 2004 23:48:29 GMT
Re:question: repeat/untilj := 0; repeat j := j + 0.5; i := j; until j = 10; "y_jim542...@yahoo.com" <u246063...@spawnkill.ip-mobilphone.net> wrote in Quote> HI, |
Virgi
Delphi Developer |
Sun, 29 Aug 2004 05:15:55 GMT
Re:question: repeat/untilIn article <hrpj8.3509$_L.2...@news1.bloor.is>, "John Blackwood" <jb_cornfl...@hotmail.com> wrote: Quote> j := 0; should read until j >= 10;your loop may not end may exit proiperly. |
Sven Pra
Delphi Developer |
Sun, 29 Aug 2004 17:06:01 GMT
Re:question: repeat/until"Virgil" <vmh...@attbi.com> wrote Quote> > > does i ever become equal to 10?. if not, how can i make j will be exact 10.0 It may become 10.0000000001 in which case your original code and it may become 9.999999999 in which case both codes will The safest code is to count by integers, but if you must step a regards Sven |
Bob Scho
Delphi Developer |
Sun, 29 Aug 2004 22:11:08 GMT
Re:question: repeat/untilMy personal preference is to write a function, call it "IsEqualTo", and let it do the work of comparing reals. This allows you to "hide the details" as you wish. Note that there are multiple ways to define this function -- the following is an example: FUNCTION IsEqualTo (a, b : real) : boolean; CONST BEGIN { IsEqualTo } Now, the loop would end with UNTIL IsEqualTo (j, 10); Bob Schor QuoteSven Pran wrote: |
Sven Pra
Delphi Developer |
Mon, 30 Aug 2004 03:31:47 GMT
Re:question: repeat/untilQuote"Bob Schor" <bsc...@pitt.edu> wrote in message Quote> My personal preference is to write a function, call it "IsEqualTo", and be relative, not absolute: IsEqualTo := abs(a-b) < tolerance * abs(a); regards Sven |
Huub van Doore
Delphi Developer |
Mon, 30 Aug 2004 05:51:44 GMT
Re:question: repeat/untilJohn Blackwood heeft geschreven in bericht ... <snip> Quote>"y_jim542...@yahoo.com" <u246063...@spawnkill.ip-mobilphone.net> wrote in I think you are confusing integers with reals. After 20 steps <j> becomes 10.0 (real). (tip: use i,,j and k for integers and r1,r2, a,b,c for reals, k:=0; {new integer i} or maybe this: for i:=0 to 20 do Huub. |
Bob Scho
Delphi Developer |
Tue, 31 Aug 2004 02:03:02 GMT
Re:question: repeat/untilThat's the beauty of the functional approach. You can design the test that is most appropriate for the occasion! Bob Schor QuoteSven Pran wrote: |
torste
Delphi Developer |
Fri, 24 Sep 2004 04:38:18 GMT
Re:question: repeat/untilHi, I just have read some reply's to this one and I really like some of the solves that have been suggested here. The Equality check for reals will be very useful to me on other projects, thanks guys. Now I finally got to actually try the original routine below, I thought I guess the answer is no i will never be 10 and i=10.0 on the second part Quote"John Blackwood" <jb_cornfl...@hotmail.com> wrote in message Quote> j := 0; |