Simple cycle

I have this simple loop, but unfortunately I cannot start it successfully.

This is what I have:

For the cycle

 var imagesPerPage = 2

  for (i = 0; i < response.d.length; i++) {
    if (i > imagesPerPage) {
     alert('more');
     }else{
     alert('less');
     }
  }

When I run this code firstIf I have <= 2 , I get an "less"alert twice. But when I have 2 , I get an "less"alert twiceand "more"alert message once.

Can anyone tell me where I am going wrong?

+3
source share
2 answers

Why not use a design for this if?

var imagesPerPage = 2

if ( response.d.length > imagesPerPage ) {
  alert('more');
} else {
  alert('less');
}

response.d.length . "" . if- "". , .

, break , . , , , . ( , , .)

+6

for? , :

 if ( response.d.length > imagesPerPage ) 
 {
   alert('more');
 }
 else
 {
   alert('less');
 }
+3

All Articles