Hey guys, so I am having a theotrically question.
I have for example the following codes which are doing the same:
1 2
for(i=0;i<2;i++){
if N[i]==N[i+1] j++;}
or
1 2
if N[0]==N[1] j++;
if N[1]==N[2] j++;
Is there any difference between those two(speed or something else)?
Because atm I am having some conditions which have things in common to write a loop, but a loop for 2-3 conditions seems to be more work than just writing the conditions.
Speed/performance wise, practically no. But the loop version is better. Currently you have only array of two, in real code the number of items will come dynamically, in which case you wont know how many iterations the loop will go through. It will also become unwieldy to write all these assignments by hand
Correct. Doesn't matter, there is no practical difference in speed. In other words for two-three static values not using loop is not going to give you any measurable speed gains over using loop