New To Coding/Confused about Homework Problem


I have two questions relating to one problem given. I am very new to all of this and relatively stuck.


x = 0
y = 0
   DOWHILE y < 2
      y = y + 1
      Print y
   x = x + 1
   Print x

How many numbers will be printed out after executing the above algorithm?
a 2
b 3
c 4
d 6
e 8

What is the fourth number to be printed out?
a 1
b 2
c 3
d 4
e 5

My guess for answer one would be two, but I have a feeling I am not reading into it as much as I should. Considering there is a fourth number to be printed, the answer of 2 has to be incorrect.

Anyone care to answer and explain this further? Or help me walk through this so I understand?


Not sure what language this is...

Try sticking it into a console, if you're allowed. That usually helps. :stuck_out_tongue_winking_eye:


My teacher wrote this herself. Many of us in the class have a hard time understand what it is she wants being that her native language is not English. Sometimes her questions are a bit confusing and use the wrong words.

The problem is related to my text book, Simple Program Design: A Step by Step Approach by Lesley Ann Robertson, and uses pseudocode. Part of our class also mainly deals with PHP related stuff as well.


I've tried running it, but keep getting syntax errors. :confused:


I see... This doesn't look like PHP. I'm thinking pseudocode, but I'm not sure.

I rewrote it in Python:

x = 0
y = 0
while(x < 2):
   while(y < 2):
      y = y + 1
      print y
   x = x + 1
   print x



From there, the answers should be pretty straightforward.

Hope this helps you. Enjoy. :slight_smile:


(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)


this is absolutely pseudo code.

given @825orion has written it in python, you might want to run it here, this program will it in steps, so you can see what is happening.

What language are you guys coding in?


Have it here for you. :wink:


you also posted it on the forum, i am sure jbhugs12 can copy paste it into the python visualizer :slight_smile: (no offense intended)

the python visualizer allows you to run the programs into steps, to better understand it :slight_smile:


Aha. Thanks for the link. I'll be sure to start doing it there, help guys out more. :smiley:


I honestly don't understand much of this at all. Programming really isn't my thing, nor is coding anything. But it's required for the degree and I'm doing my best to understand. When I get back on my computer, I will run in as you guys suggested so I can understand better.

Thank you for the replies.


what language are the assignments in? You could only find tutorials in this language, to better understand it, otherwise you might get difficulty with completing your degree


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.