You are Here: Home

# Pascal For Loop Help Watch

1. I am doing AQA Computing and I am using Pascal with Delphi. I understand all of the basic stuff and have been practicing for some time, and I can do the Repeat and While loops, but i just don't understand the For loop.

I can do basic for loops, for example "Display Hello 5 times" or "Ask the user to input a message and how many times they want to display it, then display the message that number of times". But I can't do past this.

For example, one question I am trying to do is "write a program to display the squares of all the integers from 1 to 12 in two columns labeled number and square number".

If anyone can do this, can you put your code in the reply?
2. I don't know pascal so can only provide pseudocode.

Go to your "Display Hello 5 times" program and do the following:

1) BEFORE the for loop output the string literal: "Number" followed by a tab followed by "Square Number". This is your title.

2) Make the for loop say Hello 12 times instead of 5. The obvious way to do this is using a variable initialised to 1 and iterating until the condition "variable does not equal 12" is untrue. If you can say hello five times you should be able to do this.

3) Change saying hello to writing: the number, a tab, the square of the number and then a newline.
3. You can easily put code within a for loop to do a simple calculation as you are describing, e.g.

var
i : Integer;
isquare : Integer;

begin
// Loop 12 times
For i := 1 to 12 do
begin
isquare := i*i;
writeln('number = '+IntToStr(i)+' square = '+IntToStr(isquare));
end;
end;

Note: I haven't used Pascal for a very long time, and don't have a compiler on my PC now, so take the code with a pinch of salt, but it should help with the gist of it.
4. Thanks to everyone who replied

I literally cracked the loop this morning, but thanks anyway. I think tangledweb, that would work.

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.

This forum is supported by:
Updated: April 14, 2013
Today on TSR

### What is the latest you've left an assignment

And actually passed?

### Simply having a wonderful Christmas time...

Discussions on TSR

• Latest
• ## 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
Useful resources

Can you help? Study Help unanswered threadsStudy Help rules and posting guidelines

## Groups associated with this forum:

View associated groups
Discussions on TSR

• Latest
• ## 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

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