need some help with code(noob)

Started by
11 comments, last by scrap 12 years ago

nevermind i fixed it now smile.png, with break it ends the loop and closes my program but i made a new line that says, if you dont try Y or n or N or y then it askes again...bu thanks, i learned a new keyword break smile.png

Excellent :)
Yes break makes you go out of the current loop. It's useful because it often allows to simplify stuff like exclusive conditions. There are other useful keywords like "continue" which directly goes back to the first instruction of the loop and increments the counter if it's a for loop.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement
Hi Scrap, I just wanted to mention something that would hopefully make your life easier in the future. When comparing characters such as y, Y, n, and N, you can force the comparison to be either all lower case or all upper case which would be useful in this instance.

You could turn the following:
if (again1 == "n" || again1 == "N")

into:
if (again.ToUpper() == "N")

and it would take whatever was in the variable 'again' and capitalize it for the comparison. It's important to note that it wouldn't save it as upper case beyond this statement. For that you would need to do again = again.ToUpper()

I hope that's helpful.

Hi Scrap, I just wanted to mention something that would hopefully make your life easier in the future. When comparing characters such as y, Y, n, and N, you can force the comparison to be either all lower case or all upper case which would be useful in this instance.

You could turn the following:
if (again1 == "n" || again1 == "N")

into:
if (again.ToUpper() == "N")

and it would take whatever was in the variable 'again' and capitalize it for the comparison. It's important to note that it wouldn't save it as upper case beyond this statement. For that you would need to do again = again.ToUpper()

I hope that's helpful.
yes! thank you. always learning more everyday.


thank you all for your replies :)

This topic is closed to new replies.

Advertisement