Board index » delphi » "odd" statement
Mark G. Fran
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
|
Mark G. Fran
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
"odd" statementI am stuck, I am trying to get the odd integer only from a field 11 to var Loop:integer; procedure OddLoop (eleven:integer); I've tried without procedures, different variables, etc... I've been Thanks, M |
Mike Copela
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:"odd" statementQuote> I am stuck, I am trying to get the odd integer only from a field 11 to made an attempt to do it yourself - putting yourself light years beyond the usual person who comes here "for" such help. Accordingly, here is some: for Loop := 11 to 23 do You see, Loop cycles/iterates from 11 through 23 (13 times), with Loop |
Mark G. Fran
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:"odd" statementQuoteMike Copeland wrote: knew I should use "odd()", butwas unsure of how to use a boolean call for an integer value. As far as class goes, this is a corespondance course so it's even more difficult, if I was in a classroom, I could ask the professor, so I think I feel humbled to use the newsgroup as a instructor, I hope thats alright. I will not ask for answers, but assistance or guidance will be appreciated ;-) M |
Glenn Grotzing
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:"odd" statementOn Thu, 11 Sep 1997 16:40:54 -0700, "Mark G. Franz" Quote<mark.g.fr...@cpmx.saic.com> wrote: begin with. It writes all numbers to begin with whether odd or even (at first glance, read on those who want to oh so prove me wrong!), and as you said you only want odd numbers in your range.... the next thing is that you're using a stock system function which First thing I'd say is go ahead and think about what you're trying to Free thought in logic: 1) go through all numbers 11 to 23 and pick out the odd numbers. Looks OK, not quite as elegant as it can get, but it'll work....other 2) 3) Use algebra... Lots of combinations there to get your odd # set. |
Mark G. Fran
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:"odd" statementMany thanks to all who provided input into solving this problem, here is program ForLoop11To23; {Prints only the odd numbers between 11 & 23} var Loop:integer; begin Please provide any responses that may clear up any "oddities" that may Thanks again, M QuoteGlenn Grotzinger wrote: |
Mike Copela
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:"odd" statementQuote> Many thanks to all who provided input into solving this problem, here is Unless it was part of the assignment (and there's no apparent reason for it to be), this statement is completely unnecessary. It is important to note that, following the termination of a For loop, the value of the control variable ("Loop", in this case) is _undefined_. It should not be used for any purpose where a value is to be known (e.g. it's NOT 23, 24, or anything you'd expect or hope it to be), and you should consider it to be only an uninitialized variable at that point. Quote> end. |
Stephen Pos
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:"odd" statementOn Mon, 15 Sep 1997 11:25:41 -0700, "Mark G. Franz" Quote<mark.g.fr...@cpmx.saic.com> wrote: "for Loop := x to y do" will start Loop at any x and end at any y that are legitimate values var Quote> if odd(Loop) then {Checks the variable for an odd true} dead code, you assign the variable and immediately the program ends. Quote>end. Stephen Posey |
Dr John Stockto
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:"odd" statementIn article <341df071.10886...@news.concentric.net> of Tue, 16 Sep 1997 Quote<slpo...@concentric.net> wrote: perfectly legitimate to have y less than x, but in that case Loop does not end at y, and the [compound] statement after "do" is not executed. And vice versa for downto. -- |