C
C#2h ago
Rethae

is this not a proper use of elseif

i was pretty sure i was doing it just as the cirriculum did before, but all it activates is the daysUntilExpiration <= 10 message
No description
No description
12 Replies
Rethae
RethaeOP2h ago
No description
Rethae
RethaeOP2h ago
am i supposed to put the else if's into a block? also its apparent to me i used my escape sequences wrong i fixed it by swapping the place of the == 0 with the <= 10 I assume if statements take absolute priority, and disregards elseif if it flags as true
blinkbat
blinkbat2h ago
first off, fix your indentation no. it simply follow the first branch in an if/elseif/else that it finds true. yes, because 5, 1, and 0 are all less than ten (if you passed something in that range), so that condition gets satisfied first and the block exits. to do what you likely want, reverse the order -- >= 0, 1, 5, 10
Rethae
RethaeOP2h ago
i ended up doing that
blinkbat
blinkbat2h ago
and you understand why?
Rethae
RethaeOP2h ago
i mean yeah, just initially though it was some cureall code for if statements i guess, idk learning about arrays now and going to implode
blinkbat
blinkbat2h ago
idk what you mean by cure for ifs
Rethae
RethaeOP2h ago
like...just throw everything in there and not have to worry about it
blinkbat
blinkbat2h ago
no, the order matters here. alternatively you could use all ifs and return, if you know about returning.
Rethae
RethaeOP2h ago
theyve barely touched on returns so far will have to wait for that i guess
blinkbat
blinkbat2h ago
ok, but just know what i said -- in an if/elseif/else chain, the first block with a satisfied condition runs, and none of the others.
Rethae
RethaeOP2h ago
yep, thanks

Did you find this page helpful?