Can a termination variable in a condition of for loop be changed inside
the loop?(Java)
in Java, when using a for loop, you need to write a termination condition
of course. This is my for loop:
for(int i=1; i<=infix.length()-2; i++){
if(infix.charAt(i)==' '){
infix=infix.substring(0,i)+infix.substring(i+1);
}
(infix is a string i got as a parameter). As you can see, I'm using
substring inside the loop, which shortens the length of infix, which means
that the termination condition of the loop is changed after every single
iteration.
My question is this: Is the value "infix.length-2" saved at the beginning
of the for and doesn't change later on? Or it changes every time, and if
so, what happens with i? When will the for stop? Is there a chance for an
index out of bounds or something like that?
Thank you very much in advance! :D
No comments:
Post a Comment