21 — Progress — showing how far along you are
A long job should show how far along it is. With nothing on screen it looks like the program has stopped. One bar is enough — a bar that gets one block longer with every step.
Steps
A bar is one block repeated. It is the same sentence as in guide 20:
run it →set block to * show block repeated 3 timesYou get
***.To choose the length you need to know which step you are on. Adding
with placeto a list loop tells you:
run it →set jobs to list of reading, adding up, saving for each job in jobs with place show place show job endYou get
1andreading, then2andadding up, then3andsaving. Places are counted from 1.Use that place as the length. One block on the first step, three on the third:
run it →set block to * set jobs to list of reading, adding up, saving for each job in jobs with place set bar to block repeated place times show bar endEach bar is one longer than the last, but they pile up.
Clear the screen before each one so they do not pile up. That is
clear the screenfrom guide 14, and now the bar looks like it is growing:
run it →set block to * set jobs to list of reading, adding up, saving for each job in jobs with place set bar to block repeated place times clear the screen show job show bar wait 0.2 seconds endWithout
wait 0.2 secondsit is over before you can see it. A real program does the real work there instead of waiting.The whole thing:
run it →set block to * set jobs to list of reading, adding up, drawing, saving for each job in jobs with place set bar to block repeated place times clear the screen show job show bar wait 0.2 seconds end show all done
Try it yourself
Change set block to * to set block to # or set block to =. Then add more
jobs to the list — the bar gets longer to match, and there is no length to fix
anywhere.
What you learned
<block> repeated <n> timesmakes one row of a bar.with placeon a list loop tells you which step you are on, counting from 1.- Using that place as the length makes the bar grow one block per step.
clear the screenbefore each draw keeps it growing in place instead of piling up.