Computer Science Canada For loops inside nested if statements output error |
Author: | jinjin [ Sun Mar 16, 2008 4:18 pm ] | ||
Post subject: | For loops inside nested if statements output error | ||
Hey everybody, I'm back with another problem with loops and again its for Gr. 10 programming. I was supposed to write a program that asks the user for a low integer, then a high integer, and then asks the user if they want to count from low to high (LH) or high to low (HL). Then, a loop was to be outputted based on their low/high integers and their loop setting. Here's what I have:
The above program loops perfectly fine when someone inputs "LH" but if the user inputs "HL," it just ends abruptly. I have no idea why this occurs because both loops are written in the exact same way; the only difference is the variables 'c' and 'c2.' Any help is appreciated on fixing this. Thanks ![]() Regards, jinjin |
Author: | A.J [ Sun Mar 16, 2008 4:26 pm ] | ||||||
Post subject: | Re: For loops inside nested if statements output error | ||||||
it seems okay except for one tiny part:
try closing the first for loop after outputting the answer
and instead of using another if statement, use an elsif statement:
but you can't have a for loop with high..low (since high>low) but there's a word you have to add before it to tell the for loop that the numbers are decreasing ![]() see if this help |
Author: | jinjin [ Sun Mar 16, 2008 4:32 pm ] | ||||||
Post subject: | Re: For loops inside nested if statements output error | ||||||
A.J @ Sun Mar 16, 2008 4:26 pm wrote: it seems okay except for one tiny part:
try closing the first for loop after outputting the answer
and instead of using another if statement, use an elsif statement:
but you can't have a for loop with high..low (since high>low) but there's a word you have to add before it to tell the for loop that the numbers are decreasing ![]() see if this help Just what I needed - works perfect now ![]() ![]() |