Hey there! Sign in to join this conversationNew here? Join for free

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

Announcements
    • Thread Starter
    Offline

    8
    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

    8
    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.
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    How are your GCSEs going so far?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • 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.