How many time will the loop run?
for( int i = 4 ; i <= 20 ; i++ )
{
}
for( int i = 4 ; i <= 20 ; i++ )
{
}
when this code segmented is executed, the loop will run 17 times since in the first iteration the counter i is initialized to 4 then condition 4<=20 is checked and because the condition evaluates to true, the control enters the loop then i is incremented by 1 to become 5 and the condition 5<=20 is checked and since it evaluates to true, the control enters the loop and i keeps being incremented by 1 until when it finally becomes 21 where the condition 21<=20 which evaluates the false and the control exits the loop
Comments
Leave a comment