In for loop, ++i or i++ is executed after entire loop body is executed. After ++i/i++, condition is checked if it is true it will execute the loop body else will exit the loop. So it won’t make any diff in program 2 and 4.
But in case of while ++i/i++ is done in the condition itself, so it will follow the pre increment (++i) and post increment (i++)/
Pre increment – ++i → i value will be incremented first then will be used in the expression. So in program 3 it will iterate from 2 to 10 and values printed will be 2 to 10.
Post increment – ++ → i value will be used in the expression then it will be incremented. So in program 4 it will iterate from 1 to 10 but values printed will be 2 to 11.