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.
first
"less"
twice
"more"
once
Can anyone tell me where I am going wrong?
Why not use a design for this if?
if
var imagesPerPage = 2 if ( response.d.length > imagesPerPage ) { alert('more'); } else { alert('less'); }
response.d.length . "" . if- "". , .
response.d.length
, break , . , , , . ( , , .)
break
for? , :
if ( response.d.length > imagesPerPage ) { alert('more'); } else { alert('less'); }