![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0
![]() |
Little bit of pascal help
Ok so I found out I might be learning pascal for AS Computing. So I started looking at it late last night and ive found it easy enough so far. I have one problem though, I can't work out how to reuse a previous set of code for a later section of the program.
1: program XIF
2:
3: var value: integer;
4:
5: begin
6: Writeln('Please enter a value for x:');
7: Readln(value);
8: if value > 5 then
9: Writeln('Input accepted');
10: else
11: Writeln('Invalid input, try again:');
12: At this point it would return to line 7
13: (to read the input as the value var).
14: End.I did google the problem and looked at some tutorial sites, but things like these wouldnt work: CONDITION:
Readln(value);
if value > 5 then
Writeln('Input accepted');
else
Writeln('Invalid input, try again:');GOTO 7; Btw I am using Turbo Pascal (just for the info). |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
Did you look up how to write procedures using pascal? I'm not sure if those are what you want, but when I think of reusable code, the first thing that comes to my mind is functions/procedures/sub routines, whatever you want to call them.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Sep 2006
Location: UK
Posts: 20
Rep Power: 0
![]() |
A Level Computing is not just about programming. If you are good at programming or have a natural ability you will find the AS course boring and simple. A2 is more demanding but still is not too hard for someone with some intelligence. Most people will start it thinking its all programming and probably wont have much experience in programming either. Take a shot gun into theroy lessons to shoot the person who has a huge ego and always answers questions incorrectly(there is always one, two years with this idoit who would never shut up really put me off theory lessons).
Firstly find out what language is taught. It might be pascal, but it could be VB6/.net. Secondly get a book on the language you will be taught. Read it through and then you will find that what you want to do is very easy to accomplish. Thirdly let your teacher teach you the basics. You might not even need a book if the standard of notes and teaching is good. If you have a good teacher you will understand more easily and you can ask questions just like this to them. Good luck |
|
|
|
|
|
#4 | ||
|
Programmer
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0
![]() |
Quote:
Quote:
If you mean someone in my class: lol If you mean me: I do not have a huge ego, you might have interpreted what I typed completely wrong. And I do enjoy theory alot anyway, theres no one in my class that always answers questions wrong (ppl normally go quiet and wait for the teacher to give them the answer if they arent sure what it is lol). Thanks for the advice anyway ![]() |
||
|
|
|
|
|
#5 |
|
Newbie
Join Date: Sep 2006
Location: UK
Posts: 20
Rep Power: 0
![]() |
No you have got me all wrong. I was just telling you what A-Level computing is like. I did it a few years ago. You will find that 2/3 of all lessons will be theory. Its very boring at times. Just learn the material and you will be fine. The exams in the first year are largely based on theory and one is parly based on a project.
I was not saying you have a huge ego. I think what you are doing is a good idea. Learning in your own time shows you have a healthy interest in programming and it will come in handy. By asking for help in this forum you have shown that you have no huge ego. ![]() I had a kid in my class for two years who was so anoying. When the teacher would ask a question he would just burt out some random rubbish that was normally very inaccurate without being asked. He would even randomly add to what the teacher was saying without any question being put forward. He was a poor programmer. He was always getting pissed off with me as I would complete the task set quickly and correctly in practical sessions. He would then try to show that my code was wrong just to make himself look good and he never succeded at that. In the end I told him to shut the fuck up. I did it out loud in class when the teacher was going over something I found interesting and wanted to understand. He kept interrupting and it was anoying everyone. The funny thing was he then stod up and left the room and I was told by the teacher that he had wanted to say that all year but could not swear at a student. I was in a bad mood that day, I was wrong to say it out loud. Anyway. If you know the answer then answer when asked. Dont be a smart ass or you will make everyone else look at you when the teacher asks a question. I had this very issue in Chemistry. Its not good, as in the end even the teacher will ask you for an answer even if you have not put your hand up. |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Check out procedures and functions. They're not easy, so I'm not going to go into depth - that's what books and teachers are for - but they're basically ways of modularising code so you can re-use it. Look 'em up.
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0
![]() |
Thanks lads, bored in a 'study period' (nothing to study this time of year) at the minute so i might as well look em up now
.Thanks again ![]() |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0
![]() |
A hell of alot easier than I first thought it would be, i just needed to use:
repeat
<statements>
until <condition>Thanks for the advice ^^ |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You still need to look up procedures. They can be invoked from any point, whereas your example only reuses the code at that one particular place.
![]()
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Nov 2005
Location: Belfast
Posts: 34
Rep Power: 0
![]() |
Thanks for the advice DaWei ^^
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pascal? | Indigno | Other Programming Languages | 14 | Sep 24th, 2006 2:38 AM |
| Object Pascal Q: object instance as parameter | KodeKid | Delphi | 1 | May 16th, 2006 12:06 PM |
| Images in TURBO PASCAL | S_A_L_M_A_N | Other Programming Languages | 4 | Dec 20th, 2005 9:38 AM |
| Need help badly: Pascal conversion to C | joan400 | C | 0 | Apr 12th, 2005 9:48 PM |
| Delphi as opposed to Pascal? | peace_of_mind | Delphi | 8 | Apr 2nd, 2005 8:23 AM |