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

Announcements
    • Thread Starter
    Offline

    3
    ReputationRep:
    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!
    Offline

    1
    ReputationRep:
    "for" indicates that the code should loop, so the code on the next line should run once for each value. eg
    Code:
    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
    Code:
    for a = 8 to 19 step 4
        print a
    would print 8, 12, 16.
    • Thread Starter
    Offline

    3
    ReputationRep:
    (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
    Code:
    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
    Code:
    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?
    Offline

    1
    ReputationRep:
    (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.
 
 
 
Write a reply… Reply
Submit reply

Register

Thanks for posting! You just need to create an account in order to submit the post
  1. this can't be left blank
    that username has been taken, please choose another Forgotten your password?
  2. this can't be left blank
    this email is already registered. Forgotten your password?
  3. this can't be left blank

    6 characters or longer with both numbers and letters is safer

  4. this can't be left empty
    your full birthday is required
  1. Oops, you need to agree to our Ts&Cs to register
  2. Slide to join now Processing…

Updated: September 26, 2016
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Poll
What is your favourite day of the week
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Quick reply
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.