|
i've just found other loops more usefull, i understand what they're for, just never found a situtation nwhere they're the best fit, in the above i would have use while copies > 0, and not had to check what the value of copies was as long as i checked the user input to make sure its a number, depending on how they were allowed to enter it. i've known people who have been doing thise for 15 - 20+ years and they have to go out of their way to use one. maybe it got ingrained in my head at some point to not think using post checks, and to always use prechecks..i dont know.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I can probably count on one hand the number of times I have had to use do/while , and probably on all fingers and toes the number of times I used just a while (which correlates almost exactly to the number of times I have had to write a TCP server, and then it still has a goto or 2!).
|
|
|
|
|
|
Yeah - I once had a user backing up their data, every day, to floppy for six months. Then they had a crash and needed to restore and the restore didn't work. I had to go over to see what the issue was...
I Start restore
"Insert Disk 1"
I ask for the first floppy, and insert it...
"Disk 20 of 20: Please insert disk 1 of 20"
I ask for the first floppy..
"Oh, there's only one." says the user.
"But this is disk 20" quoth I.
<snip -="" long="" and="" confused="" conversation="" ensued="">
"So," i calmly stated "when the backup program said 'Insert Disk 2 then press Enter to continue.' you pressed Enter. Then when the message **Warning disk will be Formatted - All data will be lost**', you just pressed Enter again?"
"Yes." replied the user, in a tone which suggested that only a fool would do anthing else. "and the same for disk 3, and 4 ... We thought it was clever to fit all that data onto one disk! Isn't that what formatting means?"
I suppose I should have realised they weren't the smartest bunch on the planet when, in previous years, they had folded an old 5 1/4" diskette in half to send through the post (and stapled a with-compliments slip to it) and seemed surprised that I couldn't read it!
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
Ah, tech support just isn't as much fun as it used to be.
|
|
|
|
|
Nope - but we still use the "Have you tried switching it off and back on again" trick
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
you mean they didn't want 4294967294 copies??? (till it reached zero again)
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
I used to work with a guy who was clever enough to write this:
For i = 1 To 5
If i = 1 Then
...
Else If i = 2 Then
...
Else If i = 3 Then
...
Else If i = 4 Then
...
Else If i = 5 Then
...
End If
Next i
I guess the coder wanted to do something "in five steps". He certainly does.
We don't work together anymore
|
|
|
|
|
Maybe there is a i++ in some states in the if blocks to skip steps?
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
Nope, the i did nothing else
|
|
|
|
|
How else would he know what step he was at? Now he can simply refer to i in the debugger!
|
|
|
|
|
While a select-case statement would probably be better than the cascaded if/else-if, the illustrated construct may not be unreasonable in certain cases where it is expected that the inside of the loop will be pulled out into a separate routine for use as a state machine. Having the code within a for-next loop may be handy during development while the code is being perfected, even if the final construct will be something else.
To be sure, when running on a PC it's often easier to use threads rather than state machines, but state machines can often have a much lower 'footprint'. If an application will require hundreds or thousands of objects each with a multi-way state machine, and all have to be operable concurrently, a select-case state machine may be a reasonable approach. Delegates should be considered as well, since they have some advantages (but also some disadvantages), but state machines are reasonable in simple cases.
|
|
|
|
|
Wow...
Just wow...
Where in the original WTF did it mention a problem that would require State Machines or Threads to solve?
You've created a mountain out of a grain of dirt.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Tristan Rhodes wrote: Where in the original WTF did it mention a problem that would require State Machines or Threads to solve?
My point was that there are circumstances where code like that illustrated may be useful. While it is true that there was nothing to indicate that such circumstances applied here, I would not wish to condemn code without knowing that such circumstances did not apply.
BTW, another circumstance where such code may be useful is in cases where the loop will evolve into something like:
for i=1 to 5
.. do some stuff in every case
if i=1 then
.. handle first case
else if i=2 then
.. handle second case
... etc
end if
.. do some more stuff in every case
In many circumstances, that style of code could be handled better by putting the different parts into subroutines and just calling them:
everycase_prep()
.. handle first case
everycase_cleanup()
everycase_prep()
.. handle second case
everycase_cleanup()
In some cases, however, the prep and cleanup would need to share many local variables, thus requiring either long parameter lists or awkward class constructs.
|
|
|
|
|
Take brain – Turn off brain – Start coding.
yvind Bratland wrote: We don't work together anymore
Surprise! Surprise!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Of course you two don't work together anymore.
This guy's a visionaire! You simply cannot understand the superior maths under this construction.
Kazz
"Users are there to click on things, not think. Let the archs do the damn thinking."
|
|
|
|
|
yvind Bratland wrote: We don't work together anymore
I bet that's a good thing
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I just found this board, and just had to share...
A programmer had the job of writing a routine to perform calculations based upon fees over time (the detail's not important - essentially she needed to know the number of days between two dates, and apply an algorithm something like 'for the first 30 days, a fee of 10c per day, up to 45 days, 25c per day, from 46 through to 100 45c per day)
Now, there's 1001 ways to do it - but I couldn't believe that she produced a huge Cobol program to do it.
It contained a huge array of constants, called January1984, February1984 etc. etc. etc. wach one being the number of days in that month.
Then she had an
If FromDateMonth = "January" and FromDateYear = 1984
Subtract DateDay from January1984 Giving calcDays.
Else If FromDateMonth = "February" and FromDateYear = 1984
Subtract DateDay from February1984 Giving calcDays
etc.
etc.
for every month of every year for about ten years.
THEN she repeated the same set of If's for the end date.
THEN she repeated the same set of If's, in a loop, for each month in between!
I couldn't believe that any programmer could be quite so dumb! When asked, she just said she couldn't think of a better way of doing it! (Oh, it had taken her nearly two weeks to do - I had estimated a day, and allowed her a week, as she was new to the company, though not to Cobol)
And sure, I should have looked at the code before she got so far - but she wasn't a junior (and she never became a senior)
(Oh and excuse my code - it's been a long time since I did Cobol and can't really remmeber the syntax)
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
maxxx# wrote: but she wasn't a junior (and she never became a senior)
I bet after that she was not even employed anymore, was she? :P
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: I bet after that she was not even employed anymore, was she?
Now she is the boss lover, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I bet you she is not taking leap years into account.
|
|
|
|
|
Strangely enough she was!
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
It is a good thing she did not try to take into account that years ending in hundreds area not, but thousands are. The control code would have been smaller, but the array would have had 12000 entries.
Silver member by constant and unflinching longevity.
|
|
|
|
|
I'm pretty sure that, given thetime, she would have!
And the actual calc is that 'century years' are leap years when divisble by 400 - so 2000 was, but 3000 isn't
Take a chill pill, Daddy-o
.\\axxx
(That's an 'M')
|
|
|
|
|
It does look like she was trying to be very through, so I am not suprised that she accounted for leap years. What this really points out is that it is not enough for a programmer to be able to write code that works; we also have to be able to come up with fast and efficient ways to solve problems.
Bill
|
|
|
|