Computer Science Canada Loop Execution Program |
Author: | compudave [ Wed Nov 12, 2003 11:00 pm ] | ||
Post subject: | Loop Execution Program | ||
I can't believe I actually got this far in my programming question anyways I'm having trouble with this program. I can't get it to exit when the user types "exit". Some help on my error please. Sorry 'bout the comments, I just like to be detailed when I type them. ![]()
|
Author: | poly [ Wed Nov 12, 2003 11:23 pm ] | ||
Post subject: | |||
I Just read over your code and you have a variable called MORE and its not even used in the program. Here is a loop program that I have lieing around my PC from last years programming, you can get an idea on how its done. In my example though if user types word longer than 4 characters than program crashes
|
Author: | AsianSensation [ Wed Nov 12, 2003 11:28 pm ] | ||||
Post subject: | |||||
the problem is at when you had the elsif statement, you had
of course the input will always equal to the input, because it checks to see if "more" is the input, and then if it's not, it goes into the elsif statment, and it will always be true. therefore, do this:
this will check for the 2 cases, whether if the input is "more" or "exit", and if it's not any of those, then it display the error msg. I don't get why you need the loop end loop there, you can run this program fine without using the infinite loop, either way, you only need one loop, the for loop, or the infinite loop. |
Author: | compudave [ Thu Nov 13, 2003 12:51 am ] |
Post subject: | |
yeah, I knew the problem was with my elsif statements. Man it's been a while since I've done this. I took out the initiating loop and it works fine now. Thanks a lot guys. Asian Pride man:lol: |
Author: | AsianSensation [ Thu Nov 13, 2003 5:02 pm ] |
Post subject: | |
lol, Asian Pride indeed here, have some bits. Give compudave some bits btw, what school do you go to in Windsor? I'm from Windsor too |
Author: | compudave [ Fri Nov 14, 2003 1:32 pm ] |
Post subject: | |
I attend Catholic Central High. |
Author: | AsianSensation [ Fri Nov 14, 2003 4:54 pm ] |
Post subject: | |
cool, I go to Massey |
Author: | DBZ [ Wed Nov 19, 2003 8:26 pm ] |
Post subject: | |
hey i looked at ur program and u haven't told the computer when to exit. you've just used the if statement and said that else if exit. Why don't u tyr using the 'exit when' statement? hope it helps! |
Author: | santabruzer [ Wed Nov 19, 2003 8:33 pm ] | ||||
Post subject: | |||||
I agree with DBZ... you have to but and if statement for exit... for example:
and somewhere outside the 'for'
I don't understand why you use a for statement.. it would be much easier using a loop with a counter... Santabruzer |
Author: | Tony [ Wed Nov 19, 2003 8:59 pm ] | ||
Post subject: | |||
I dont think you guys should argue with AsianSensation... he got experience with turing.
is a better way. Exit when is really another way of having a separate if statment. |
Author: | AsianSensation [ Wed Nov 19, 2003 11:50 pm ] |
Post subject: | |
santabruzer wrote: I don't understand why you use a for statement.. it would be much easier using a loop with a counter... lol, isn't a For just a Loop with a counter and an automatic exit condition? (exit when the counter in at certain place) anyways, I guess I could have done that, but saving one line of coding space and not actually making the program more efficient isn't much to argue over isn't it? Besides, it took me less time to change his code than to write new ones yeah, I know, I'm a lazy bum 8) |
Author: | santabruzer [ Thu Nov 20, 2003 12:10 am ] |
Post subject: | |
Can't argue with the turing guru.... unfortuantly.. but i'll get there some day ![]() |
Author: | Tony [ Thu Nov 20, 2003 12:14 am ] |
Post subject: | |
heh ![]() As for the loops vs forloops... well its preaty much the same really. But forloops look more organized and easier to understand when reading the code. |
Author: | Andy [ Fri Nov 21, 2003 7:02 pm ] |
Post subject: | |
here is a tip, never learn turing in the first place! go straight to vb or c++, if u want to major in compsci in university, you dont even need a compsci credit from high school |