need help with looping

Hey Guys, I am not a programer at all but i came across a code that helped me to create a slider.

that is the code

$w . onReady ( function () {
setTimeout ( loadSlider , 6000 )
});

function loadSlider ( ){

**if** ( $w ( "#dataset1" ). getCurrentItemIndex ()=== 5 ){ 
    $w ( "#dataset1" ). loadPage ( 1 )          
} **else** { 
    $w ( "#dataset1" ). nextPage () 
} 
setTimeout ( loadSlider , 6000 )  

}

everything is workin fine but when it comes to the last data form my dataset it’s brakes and stop.
how can i loop it?

I am confused by this code. The reason why it is not working though is because when you reach the end of the dataset there is no other items left to call nextPage on. You should be able to just chain the else in another if statement like so:

functionloadSlider(){
    if($w("#dataset1").getCurrentItemIndex()===5){
    $w("#dataset1").loadPage(1)
    }else{
        if($w("#dataset1").nextPage()) {
            $w("#dataset1").nextPage()
        }
    }
    setTimeout(loadSlider,6000)
}

I don’t think that this is necessarily the best solution but given the context this is the best I can think of.

I might be able to come up with a better solution with more information

Thank you - that was helpful