LOOP IN PASCAL Course
In our daily lives, we find many things happen again and again creating a pattern. For example, your alarm clock always rings every morning. When we set the time we decide when it should ring. Most alarms have automatic feature so that we don't have to set it every day.
The same idea works in programming. Instead of writing a single similar command many times, we can choose and use the repetition functions to do this. In programming we call these loop commands. This module is the next in our algorithm and programming course, after data type, basic commands and branching. Our goal in this course is learn together how to solve a real world problem using loop commands.
This course will require 3 weeks to be completed. Our face-to-face (FTF) class session will be take place 1 during first and third weeks, meanwhile you will work on online activities during week 2 and 4.
After completing this course, students are expected to:
- Given a real world problem that needs to be solved using loop structures, first year undergraduate students will be able to analyze the problem, create solutions using loop commands using Pascal language.
- First year undergraduate students will be able to reflect their understanding of loop commands by identify another real world problem and solve it.
Note: although this FTF unit is presented in web setting lecture and activities will be done in classroom setting.
Recall that every time we code we should always consider the user' point of view. They might know nothing about programming, but they do need to know how to use the program.
As we have learned before, if we want 'Number 1' to appear 10 times on the screen then we should write it 10 times in source code.
Try to figure out these questions:
- How we print 'Number 1' through 'Number 1000'?
- How we print only 'Number 1' through 'Number 5'?
- How we ask user to input certain numbers (total of numbers are depend on user) and show them on the screen?
We can probably do this manually by writing 1000 line of codes or by changing code based on user requirements but it will waste of time and make you bald :) That is why we need loop commands to make it simple.
B. Lecture Notes
Lecture notes for this course can be downloaded at Looping
C. Group Activity
The main problem to solve for this module is:
"Mr. A wants to have a saving account . He plans to add $100 every mount. He wants to know amount of his money in first, second, third, fourt, and fifth years later if he have 2%, 3%, 4%, or 5% monthly compound interest. How will you solve his problem with Pascal?"
General output of the program should looks like this:
|After 1 year||xxxx||xxxx||xxxx||xxxx|
|After 2 years||xxxx||xxxx||xxxx||xxxx|
|After 3 years||xxxx||xxxx||xxxx||xxxx|
|After 4 years||xxxx||xxxx||xxxx||xxxx|
|After 5 years||xxxx||xxxx||xxxx||xxxx|
You should work in groups (4-5 students), choose a group leader, and discuss this question:
- What is the appropriate formula to solve it?
- Every member should choose one of the loop commands to solve the problem. You will work on coding process in online activity.
- Every loop command should be chosen, at least, by one member.
- Post the answer on group discussion forum on Moodle and discuss it with peers.
- As you experienced in this sample of real problem, there are many ways to solve one problem. All programming languages have different looping syntax but they are similar. For example, 'for' in java, C, & php has a syntax "for(initialization; Boolean_expression; update)" while in visual basic is "For initial to end (Step increment)". They might have slightly different syntax but have similar rule and function.
- Several factors to consider while using loop command are:
- Initial expression
- End expression
- Counter decides direction of looping and direction depend on sign or formula in counter. Could be up or down, more or less, + or -, etc.
- Counter can be numbers or formula. Counter decides distance between loop.
- Nested Loop
- In repetition strategies, we can use repetition in repetition that we called Nested Loop. See Web Resources on Moodle for examples.
- Recursion is advance topic in repetition. We are not going to cover it in this module but I give you the general analogy about recursion. See the example below.
- Recursive humor
- "See "Recursion".
- If you still don't get it, see "Recursion".
- Recursion is repetition that repeat itself. Recursion happen when we define certain repetition step as function and call the function from inside the function itself.
In order to reflect this lesson in more real world problems, you should send another real world problem example. Solve the problem using loop command (I recommend you to choose problem that need 'Nested Loop'). Your answers also should contain algorithm and your reason for choose particular loop command. Send your answer through assignment area at Moodle.
All online units will be hosted by UAlbany Moodle.
Every student will receive unique user account to access this module. For guest user can use account below.
or login as guest.
Note: This course locates at Miscellaneous - Alex de Kweldju ETAP 623 (Fall 2011).
--This section is not for students--
Since this course has separate groups setting, normal students/users only can see general group discussion. In order to see all group discussion, you can use my user name.
A. Group Discussion
All students will be assigned to a small group discussion forum (A, B, C, or D). Based on your group assignment, every student should post their solution (program codes and output sample) and respond to others. Summary discussion will be led by the group leader who will summarize and led discuss to choose the appropriate solution. In this forum, students only can see the discussion on their group they were assigned to.
B. Whole Class Discussion
Every group will post their answer in this forum (including their arguments) and respond to others. You are expected to respond to at least 2 other postings. The responds can about offer different solution (including the arguments), using same loop command but different algorithm, suggestion for improvement, bugs report, etc. In this setting, all students can see and comment to all other students postings.
Grading for discussion will follow this Discussion Rubric