Chapter 12- Advanced Loops
ok, if you have been reading this tutorial all the way from the begining you will know understand the concept of loops, this chapter deals mostly with with nesting loops.
A simple loop:
While A<>B
WhileEnd
A nested loop:
While A<>B
Do
LpWhile A=B
WhileEnd
get it? a nested loop is just a loop inside of a loop, just like a nested if. what most people have trouble with is the execution of nested loops, if you have programming experiance then you will all ready know this but if your new to field take a look at the sample below:Lbl 1<!--QuoteEBegin-->1->A<!--QuoteEBegin-->1->B<!--QuoteEBegin-->1->C //counter var<!--QuoteEBegin-->1->D //counter var<!--QuoteEBegin-->Do<!--QuoteEBegin-->A+B->A<!--QuoteEBegin-->While D<=5 //loops 5 times<!--QuoteEBegin-->B+A->B<!--QuoteEBegin-->Isz D<!--QuoteEBegin-->WhileEnd<!--QuoteEBegin-->1->D<!--QuoteEBegin-->Isz C<!--QuoteEBegin-->LpWhile C<3 //loops 3 times<!--QuoteEBegin-->A+B_<!--QuoteEBegin-->
Go through this program and see if you can figgure out what the output will be, then look below for the answer.
if you 610 got as the output then you did this right, if not then you fell pray to a mistake that many begining programmers make (I took a C++ programming class and some people had all sorts of programs with this). If you did get this wrong its because you do not understand one of the basics of nested loops:for those of you who are looking at me like I'm stupid: trust me, some people will make this mistake, I have seen highly intelegent people make this mistake so I thought I'd save others the trouble (and frustration).PRIMARY RULE: an inner loop executes fully for each interation (loop) of an outer loop
You can nest as many loops as you want, I dont know if there is an upper limit on the amount you can nest but I cant see you ever needing to worry about it.
Now you should know what the break statement is, but if you dont I'll review: Break terminates execution of a loop and resumes normal program flow at the end of that loop.Sample: While A=A //endless loop Isz A Break "THIS ISN'T SHOWN, IT ISN'T EVEN LOOKED AT BY THE PROGRAM" "NEITHER IS THIS" WhileEnd "ESCAPE FROM THE LOOP" //Break goes to here
now we will look at how Break works in nested loopsSample: While A<>B Do Break LpWhile A=A //Break goes to here WhileEnd //loops like normal
As you can see, Break only exits the current loop, and when that loop comes around again and if Break isn't executed (if its in an if statement) then the loop does not terminate and continues like normal. Get it?
Casio Basic Tutorial
#1
Posted 31 July 2003 - 01:34 AM
#2
Posted 31 July 2003 - 04:29 PM
#3
Posted 01 August 2003 - 01:03 AM
#4
Posted 01 August 2003 - 01:49 AM
#5
Posted 01 August 2003 - 02:17 PM
the matrix and list chapter is next, that will be very useful to you for the contest.
thanks
#6
Posted 05 August 2003 - 06:32 AM
It's good that you are learning form the master Crimson, yet reading the manual already gives you a solid grounding on BASIC programming.
just read it and you'll be fine.
That's how i learned to program.
#7
Posted 05 August 2003 - 01:22 PM
#8
Posted 05 August 2003 - 03:02 PM
Part 13: Advanced Variables
Those of you who know other programming languages have probably seen a big problem in what you have read so far, what if you need more than 28 variables in your game? A long time ago (in a calc far, far away), when I was first learning to program I was making little games like Example 1 of this tutorial. But then I started trying to make some more complex games and I ran into a problem, I needed more variables and there were none to be found! Eventually I found the answer: Lists and Matrices.
Lists ? A list is exactly that, a list of variables, they can be up to 255 cells long.
Here is a visual of a list with 5 cells:
[ ]
[ ]
[ ]
[ ]
[ ]
to access a cell in a list you just use List #[#] (List 1[1]), the first # represents the number of the list and the second represents the index of the cell. You can use Lists just like you use normal variables, anything you can do with a letter variable you can do to a list, you just have to specify what list and what cell.
Some special list functions:
X->Dim List # : creates a list with X cells in it, all cells are set to 0.
Fill(X,List #) : fills a list with X.
There are others, but you probably wont use them.
Matrices ? A matrix is a two dimensional list
Here is a visual of a 5x4 matrix.
[ ][ ][ ][ ]
[ ][ ][ ][ ]
[ ][ ][ ][ ]
[ ][ ][ ][ ]
[ ][ ][ ][ ]
Matrices are just like lists except that they are two dimensional, I like to use them for maps, especially tiled maps. To use a matrix use Mat (letter A~Z)[Y,X] (Mat A[1,1]), the X and Y are reversed, make sure not to confuse them.
Special Matrix functions:
{Y,X}->Dim Mat (letter) : creates a YxX matrix
Fill(#,Mat (letter)) : fills a matrix with a #
Again, there are more, but you wont need them right now.
Tip: List and Matrices are very useful for loops, since they are indexed you can loop through them or use List 1[A] so you can change what list cell you are using dynamically. Also note that you cannot do this with the number of the list.
#9
Posted 05 August 2003 - 07:08 PM
By the way i learn a little of basic with the manual, but i dont read the matrix and list function, because i think that i will never use the lists (i was bad thinking that) and i only use the matrix on the RUN/MAT mode.
Some people learn of best way the things reading (probably the casiokingdom's case) , others with practice (thats me).
#10
Posted 05 August 2003 - 07:26 PM
#11
Posted 05 August 2003 - 10:46 PM
#12
Posted 06 August 2003 - 06:04 AM
that sounds great Crimson.thanks, happy to help. by the way, the next part is another example program followed by some exercises. after that I will go over good programming techniques.
i think i could even learn some tips from your tutorials too.
#13
Posted 06 August 2003 - 06:56 PM
#14
Posted 07 August 2003 - 06:43 AM
Good luck in the comp.
BTW; are most of you almost finished your game?
i am already almost done.
Can't wait till the end.
#15
Posted 07 August 2003 - 06:48 PM
Besides, my pc interface or my AFX serial port its damaged, i need to check that, to upload the pictures and basic files that i made...
But now my game sucks and if my main battery fail (it has 14 months of use), all will be erased.
#16
Posted 07 August 2003 - 06:58 PM
#17
Posted 07 August 2003 - 06:59 PM
#18
Posted 07 August 2003 - 07:30 PM
I change the main batteries in January , i bought 4 energizer AAA batteries. In April i dont use in 1 week my calc, and when i try to use it, i press the AC button and nothing appear. Then i check the batteries and one battery was damaged (the electrolyte was out of the battery), and the calc was nearly of have damages on the print circuit board
#19
Posted 07 August 2003 - 07:54 PM
i am only though with the opening screen
#20
Posted 08 August 2003 - 06:18 AM
come on bob, hurry up.@ kingdom
i am only though with the opening screen
BTW; my backup batteries are fine.
just replace your normal batteries straight away when you see the "low battery message"
#21
Posted 08 August 2003 - 01:08 PM
come on bob, hurry up.
oh dont worry your little buttons off, i have been finding time and will be done before you know it
#22
Posted 08 August 2003 - 06:18 PM
I need that program, i will thank your help...
#23
Posted 08 August 2003 - 06:20 PM
#24
Posted 08 August 2003 - 08:12 PM
#25
Posted 09 August 2003 - 01:40 AM
I don't have little buttons (ha!)come on bob, hurry up.
oh dont worry your little buttons off, i have been finding time and will be done before you know it
BTW: your avatar is cool.
Did you design it by yourself?
#26
Posted 09 August 2003 - 01:52 AM
#27
Posted 09 August 2003 - 01:59 AM
#28
Posted 09 August 2003 - 06:52 PM
#29
Posted 29 August 2003 - 10:57 AM
#30
Posted 11 May 2004 - 08:49 AM
#31
Posted 11 May 2004 - 02:58 PM
i really dont know, I keep making plans to work on thins but always end up not having enough time... right now im working on a big game so it wont be untill after I finish for sure.
however, you can ask questions and i will answer them.
#32
Posted 11 May 2004 - 03:29 PM
however, you can ask questions and i will answer them.
unless i get there first
#33
Posted 11 May 2004 - 04:06 PM
#34
Posted 11 May 2004 - 04:18 PM
#35
Posted 11 May 2004 - 07:06 PM
#36
Posted 17 December 2005 - 05:48 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users