The Student Room Group

Can you explain what "for a = 8 to 19 step 4" as pseudocode means in english?

First two lines of a given pseudocode are:

for a = 8 to 19 step 4
for b = 1 to 3
Im guessing that this means that "a" is in the range of 8 to 19, and "b" is in the range of 1-3, is this correct?If so, what does the "for" mean at the start if both lines? And what does "step 4 mean"?Thanks!
"for" indicates that the code should loop, so the code on the next line should run once for each value. eg for b = 1 to 3
print b
would print 1, 2, and 3.

"step 4" just means step on by 4 rather than 1, so
for a = 8 to 19 step 4
print a
would print 8, 12, 16.
Reply 2
Original post by schoolcoders
"for" indicates that the code should loop, so the code on the next line should run once for each value. eg for b = 1 to 3
print b
would print 1, 2, and 3.

"step 4" just means step on by 4 rather than 1, so
for a = 8 to 19 step 4
print a
would print 8, 12, 16.


Thanks. What do you mean by "the code on the next line should run once for each value"? Do you mean that the "for" means that if a code said "for a = 1 to 5", then the for loop would mean that if the next line was "print a", it would print 1, 2, 3, 4, 5, because it would print each value of "a" one time each?
Original post by blobbybill
Do you mean that the "for" means that if a code said "for a = 1 to 5", then the for loop would mean that if the next line was "print a", it would print 1, 2, 3, 4, 5, because it would print each value of "a" one time each?


Yes, that's exactly how it works.

Quick Reply

Latest

Trending

Trending