sachin bhikule sachin bhikule - 3 months ago 8
C Question

Multiple conditions in for loop statement

for (icnt = 1; icnt <= (ino1 / 2) && (ino2 / 2) ; icnt++)


and

for (icnt = 1; icnt <= (ino1 / 2) && icnt <= (ino2 / 2) ; icnt++)


Both
for
loops gives same output still then what is the difference between both statements ? I tried to find out flow of program, can someone explain me what is the difference

Answer

Both loops iterate the same number of times only by chance, probably because ino1 <= ino2.

The first loop iterates while icnt <= ino1 / 2 and ino2 / 2 != 0, which is very different from the second loop condition where icnt must be less or equal to both ino1 / 2 and ino2 / 2.