retrieving program memory

I am having difficulty understanding how to retrieve data from program memory. The following sketch on a Nano gives the results of 0,6,0,1 instead of 1,2,3,4. What code do I need to add to this to make the data retrieve correctly?

const  int y[] PROGMEM ={1,2,3,4};
void setup() {
 Serial.begin(9600);
}
void loop() {
int x=0;
while(x<4){  Serial.print(y[x]);   delay(1000);x++;}
}

Code tags added ( </> )

…you forgot the pgm_read_ calls and code tags.

@rbrewer

With refence to your report that your code is not displaying properly I see that you have since discovered code tags

To add to @TheMemberFormerlyKnownAsAWOL's comment, check the reference:
https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

Also check here

Seeing a working modification to the sketch I submitted would be most helpful. Like many Arduino affectionados who post here, I have spent considerable time trying to work this out before posting. The simple sketch I provided I hoped would provide an easy way to respond without going into the morass of technicalities that I have already unsuccessfully explored.

There are examples in the reference at the links provided.

sp. “aficionado”

I am assuming that I am not seeing the minor modification to my sketch requested is that no one knows how to make this simple modification, or at least those responding. The best answer I have at this point is to purchase a Due, which would solve my memory problems.

rbrewer:
I am assuming that I am not seeing the minor modification to my sketch requested is that no one knows how to make this simple modification, or at least those responding.

You assume wrong.

You were an educator?

Remember the exams where you at least got marks for showing your working?

Check out the examples at THE LINKS ALREADY PROVIDED.

rbrewer:
The simple sketch I provided I hoped would provide an easy way to respond without going into the morass of technicalities that I have already unsuccessfully explored.

Thing is, PROGMEM is innately a small morass of technicality. That's because it was an add-on for an architecture that can't access data in flash directly.

This forum is not a free programming service where you make an order, which gets assigned to someone and delivered. It's a place to learn how to solve your own programming problems. Often, people who come here expecting much less, leave with much more.

…like “for” loops.

Now you’ve done some code fiddling, post your latest attempt, I’m sure we can show you the lines that need to be reviewed.

It’s going to be a very small change - and you’ll learn something too.

Another PROGMEM reference that is quite good: Putting constant data into program memory

The problem with your sketch is quite obviously with this line:

Serial.print(y[x]);

The compiler makes the assumption that the array is stored in dynamic memory (ram), and has to be told specifically that the variable needed for the print() is in flash memory (PROGMEM). The first reply to your post pointed out the method for doing this.