Restricting an LED light in an array from moving beyond the array size

Hi all ! i have an array of 8 LED lights, hooked up to a shift register that are currently being controlled by one left and one right navigation button. When clicking the right button the light moves one light right, and when the left is pressed, it moves one step left. however, when i start going past 8, the array starts turning on seveal lights at the same time, in random order. (my suspicion is it has something to do with ASCII) All i want to do is put in a something along the lines of


however since i am fairly new to Arduino i think i am messing up the position of where this statement is supposed to be . here is the code for my "going right" button.

if(buttonState == LOW && !checkState){
checkState= true;

newguess = oldguess + 1;
navigation(newguess + '0');

Serial.print("You are on:");
guess = (newguess + '0');

else if(buttonState == HIGH && checkState){
checkState= false;


naviagtion(newguess); is a function that takes inn the position (newguess) of the user and in there is the function that turns on the LED according to the given number. The button is supposed to increment newguess by 1 when pressed. I have tried using "constrain" and putting the if statement everywhere in my code but i cannot seem to figure out where to put it. Any help is welcome !! thank you very much :grin:

Publish the full code, Don’t post snippets (Snippets R Us!)

And publish the code where you tried to use constrain or an if

Also Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)