C programmminng.................8


#1

choose the best statement with respect to following three program code snippets.
/Program Snippet 1 with for loop/
for (i = 0; i < 10; i++)
{
/statement1/
continue;
/statement2/
}

/Program Snippet 2 with while loop/
i = 0;
while (i < 10)
{
/statement1/
continue;
/statement2/
i++;
}

/Program Snippet 3 with do-while loop/
i = 0;
do
{
/statement1/
continue;
/statement2/
i++;
}while (i < 10);


#2

Actually here, you cannot say what is better than any other. We use for loop, while loop and do-while loops according to the needs of the program and the action that is performed in all the cases is same. However, for a lazy coder here, you would select for loop.


#3

All three snippets are correct but the last one is eliminated out of race because it will be executed one more time than both above. So here it is out of race. Above two can be considered options depending upon the problem or task. Both have their advantages and disadvantages over different situations. Many tests have been conducted on this and no slight difference is found . Both will generate same byte code so it is impossible to tell the best from two.