For the conditions -d and -i i use a for(int i = 1; i < args.lenght-1; i++) and the task didn't pass. I changed in i < args.lenght; just like that... and pass, but i don't understand why? If args.lenght = 10 and args[0] = "-d", from 1 to 9 I have the rest of args array. If i loop until i = 10 I am not out of array!?
Why i < args.lenght; and not args.lenght-1; ???
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
9 February 2022, 22:11
The second condition of a for loop, the boolean, is checked prior to the loop and will break the loop before it starts a new cycle when the expression is false. As an example:
This code prints the numbers 0 through 9, but not 10. This is because when i equals 10 the boolean expression 10 < 10 will be false (10 is not less than 10) and the loop concludes. +1
Angel Stefan
9 February 2022, 22:50
What a silly question to ask, is crystal clear(now!) I am used to use i <= array.lenght-1; but now because i use only < is obvious that i must use array.lenght. Tk you!
Ps: i think i need a good sleep! :)
0