0
Odd Number exercise in Loops lesson
Take number, starting at 1 give odd numbers until number is reached. Code not working! Help! https://code.sololearn.com/cfKlX5Tj4NhO/?ref=app
5 ответов
+ 3
Minor error: should be i+=2, not just i+2, or else i never actually gets increased.
That side, you've put in the conditions the "until" for when you want your for loop to end, but it takes the conditions "while" it's supposed to continue. So as written, if num is larger than 2, it'll never run... But if num is 2 or smaller, it'll run forever!
Switch to <= there and you should be good to go.
Side note, that's gonna be equivalent to i<num if you'd like to simplify. Also, make sure you're supposed to exclude num, since that's what you're currently doing.
+ 2
Oh, one more potential source of test problems: you've included a space in your output, but since writeLine goes to the next line after it's done, you probably don't want the space
+ 2
Thanks so much! That damn = was messing me up. And switching to < fixed it all! 💯
0
Artemis18x maybe this?
for(int i=1;i<=num;i+=2)
0
Ended up using
for(int i =1;i-1<number;i+=2)