How do you do this in Pascal?

Started by
3 comments, last by jakpandora 18 years, 11 months ago
Hi, I thought I would try to learn a little bit of Pascal just to get away from C++ and try something new and a little easier. I have one question though. When I want to repeat a block of code in C/C++, I just out it in a function and have that function repeat. Things seem to be a little different in Pascal though. Functions seem to be nothing more then fancy variables. My question is: How should I have a section of code repeat? I tried WHILE and DO, but that only executes the first line of the block of code I want repeated. Plus I can only use it if theres some kind of condition. Also, if anybody knows any tutorials on how to make graphics with Pascal, I would appreciate it. I am using the Dev-Pascal IDE and the free pascal compiler. [Edited by - jakpandora on May 8, 2005 7:24:18 PM]
______________________________My website: Quest Networks
Advertisement
You're probably forgetting your begin and end lines.

procedure Blah;beginend;


It's been a while since I've used pascal, so that might not be entirely correct, but it should steer you in the right direction. Same thing with loops. You need to block the code with begin and end statements.
-----BEGIN GEEK CODE BLOCK-----Version: 3.12GCS/M/S d->+(++) s+: a19? C++++ UL++ P+++ L+ !E W+++ N+ o++ K? w!O M-- V? !PS PE Y+ PGP t++ 5+++ X R tv+> b+(++)>+++ DI+++>+++++ D++G e>++++ h! r y?------END GEEK CODE BLOCK------
I'm not sure what you're rambling on about in the first part of your post, but to implement loops in pascal you can use either:

while condition do begin  // repeated code hereend;


or:

repeat  // repeated code hereuntil condition;


Where condition is a Boolean expression. Note that the while/do loop tests the condition before the block, and the repeat/until tests it after, so the repeat/until will always execute once.

You can also use for loops, though they are not as flexible as in C:

var i: Integer;...for i := 0 to 9 do begin  // repeated code hereend;


For using graphics, you will probably want to try something like SDL - have a look at the Pascal Game Development site for more information.
[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]
Pascal doesn't use { and } to delimit code blocks; it use 'begin' and 'end'. You might take a look at this link;

click

edit; oops beaten by two people...
------------------<a href="http://jsgc.sourceforge.net>jsgc
ok thanks. I was just forgetting my begin and end blocks.
______________________________My website: Quest Networks

This topic is closed to new replies.

Advertisement