|
User #158056 1186 posts
Whirlpool Enthusiast
|
Begin mainprogram this is a school task , and they said if the payment = '20' , what would the outout be. I am quit confused coz if you set cash to 100, the cash is > 50 already and doesnt need to enter the loop. and just prints 100 |
reference: whrl.pl/RbVNQc
posted 2009-Jul-3, 8am AEST
|
|
User #112740 306 posts
Forum Regular
|
I am quit confused coz if you set cash to 100, the cash is > 50 already and doesnt need to enter the loop. and just prints 100 Begin mainprogram set cash to 20 what would happen here? |
reference: whrl.pl/RbVNVz
posted 2009-Jul-3, 8am AEST
|
|
User #30842 3758 posts
Whirlpool Forums Addict
|
Some loops ALWAYS evaluate once. That is why there are several sorts of loops (Some loops may never loop). You might not want the loop to evaluate once if some conditions are met. So you have to figure out (when you are writing a program), if you want the loop to always run at least once. Your job is to workout what sort of loop this is. Maybe it is the wrong sort (or maybe it is not). |
reference: whrl.pl/RbVOhW
posted 2009-Jul-3, 10am AEST
|
|
User #31410 8661 posts
Whirlpool Forums Addict
|
just prints 100 cash = 100 Since the exit condition (cash > 50) is evaluated after cash = payment + cash, then it will print "120" |
reference: whrl.pl/RbVOnm
posted 2009-Jul-3, 11am AEST
|
|
User #29925 1298 posts
Whirlpool Enthusiast
|
The loop used in your pseudocode is a post-test loop meaning the loop is executed once and then the condition is evaluated. Therefore cash = 120. |
reference: whrl.pl/RbVOTa
posted 2009-Jul-3, 1pm AEST
|
|
User #20620 4409 posts
Whirlpool Forums Addict
|
just to elaborate on what others are saying... repeat it is a bottom driven loop. which means that it will *always* execute at least once before checking a condition. http://www.gailer-net.de/tut notice how the "until" line is executed last. if it was a top driven loop it would start until cash > 50 |
reference: whrl.pl/RbVO5e
posted 2009-Jul-3, 1pm AEST
|
|
User #255811 1445 posts
Whirlpool Enthusiast
|
Repeat Will always run the task once before evaluating the condition. While condition Will only run the task if the condition is true. If the condition is false then nothing happens. |
reference: whrl.pl/RbVO6R
posted 2009-Jul-3, 1pm AEST
|
|
User #176087 1199 posts
Whirlpool Enthusiast
|
Don't get intimidated, just read it line by line like you are a dumb computer, doing exactly what it says. set cash to 100 --- woo 100! AMD CPUs aren't as happy about things though, they tend to grumble a lot. |
reference: whrl.pl/RbVPr9
posted 2009-Jul-3, 3pm AEST
|
|
User #162600 563 posts
Whirlpool Enthusiast
|
AMD CPUs aren't as happy about things though, they tend to grumble a lot. That's not my CPU, that's my stomach. |
reference: whrl.pl/RbVPxv
posted 2009-Jul-3, 3pm AEST
|
|
User #112740 306 posts
Forum Regular
|
just read it line by line like you are acting dumb who said i was acting? :P |
reference: whrl.pl/RbVPM6
posted 2009-Jul-3, 4pm AEST
|