C
C#13mo ago
Aubrey

endless loop

Im having a problem of an endless loop happening if a number goes into the opposite direction of the stop number how do i make it show an error instead of crashing in cases like this? im learning for an upcoming exam i have atm
No description
15 Replies
SinFluxx
SinFluxx13mo ago
You could check that Add is greater than 0 and show a messagebox if not
Aubrey
AubreyOP13mo ago
but i want it to be able to go into negatives aswell
SinFluxx
SinFluxx13mo ago
But then you'll hit an infinite loop again?
Aubrey
AubreyOP13mo ago
well not if the adding and stop number are both in the negatives
SinFluxx
SinFluxx13mo ago
Oh you mean your Stop number can be <0 too?
Aubrey
AubreyOP13mo ago
yes i want it to show an error if the adding and stop numbers arent the same well yknow what i mean i hope
SinFluxx
SinFluxx13mo ago
So you'd probably need to check that either: 1) Start < Stop and Add > 0 or 2) Start > Stop and Add < 0
Aubrey
AubreyOP13mo ago
do i just do that with if? or with something else?
SinFluxx
SinFluxx13mo ago
Yeah you can
Aubrey
AubreyOP13mo ago
yeah i just decided to not allow negatives..
No description
Aubrey
AubreyOP13mo ago
although, is there a shorter way to make this? not using 2 ifs
SinFluxx
SinFluxx13mo ago
You can check multiple conditions in one if statement: if (condition1 || condition2) if (condition1 && condition2) Where || is OR, && is AND Rather than having your while loop inside the else you can also just have a return inside the if that's checking for negatives so that it never hits the while loop
Aubrey
AubreyOP13mo ago
ohh thanks for the tip
SinFluxx
SinFluxx13mo ago
So if you did want to allow negatives still you could do: if ((Start < Stop && Add <= 0) || (Start > Stop && Add >= 0))
Dharmang
Dharmang13mo ago
why handle negative? mod everything and if the stop is a negative inverse the output.
Want results from more Discord servers?
Add your server