Computer Science Canada

Loops for the Very Beginners!

Author:  ZeroPldn [ Wed Mar 09, 2005 5:00 pm ]
Post subject:  Loops for the Very Beginners!

mmk, my first post, here it goes...

Basic Loops

ok, for the basic loop, that goes on forever

loop
put "type a number
var number:real
get number
put "the number is "..
put number
end loop

this will keep outputing the number u enter, but u cant stop it unless u exit the harsh way, the top right X button (OMG!)

loop w/ exception

ok, now this is the same as the first, 'cept this one u can end the program when you type a negative number.

loop
put "enter a number"
put "if u enter a negative number, the program will end"
var number:real
get number
end if number<0
put "the number is "..
put number
end loop

ok, this one you can type a number, but as soon as it becomes negative, the program will stop.

thats all for now, if any1 sees an error plz debug as i am ne to this stuff

[/b][/list]

Author:  Flikerator [ Wed Mar 09, 2005 5:13 pm ]
Post subject: 

Put all the code in Code tags, like this;

code:
[code][/code]


EDIT

Check your code, it doesn't work..

EDIT AGAIN

Declare vars BEFORE loops. If you want to change the number to a 0 then just;

code:
num := 0


OR since you choose it again do nothing.

EDIT YET AGAIN

Welcome to the compsci forums, if you have any questions feel free to post them ^^;

Author:  person [ Wed Mar 09, 2005 6:09 pm ]
Post subject: 

welcome!!! Smile Smile

anyways most of ur code doesnt work so uv really got to edit some

Author:  jamonathin [ Thu Mar 10, 2005 6:59 am ]
Post subject: 

"end if's" are used for "if" statements, you're going to want "exit when", and put it at the end of the loop, so everything can be run.

Author:  ZeroPldn [ Thu Mar 10, 2005 3:13 pm ]
Post subject: 

omg, im so newbish... aw well i just got turing at my own house so now i can try out the bloddy programs b4 i post them, sry.

Author:  person [ Thu Mar 10, 2005 3:40 pm ]
Post subject: 

i just fixed ur code

code:

loop
    var number : real
    put "type a number "..
    get number
    put "the number is " ..
    put number
end loop


and the second prat

code:

loop
    var number : real
    put "enter a number"
    put "if u enter a negative number, the program will end"
    get number
    put "the number is " ..
    put number
    exit when number < 0
end loop


see...arnt i nice??

Author:  jamonathin [ Thu Mar 10, 2005 3:45 pm ]
Post subject: 

you are the nicest person...person...

Author:  Token [ Thu Mar 10, 2005 3:49 pm ]
Post subject: 

Also it may help to know that the 'exit when' command can be used as many times as neccisary within a loop, and that it can use the and and or statements, just little tidbits that helped me out...

Author:  ssr [ Thu Mar 10, 2005 10:05 pm ]
Post subject: 

jamonathin wrote:
you are the nicest person...person...

lol I think he is just as bored as I am
lol
just kidding
just kidding
anyway
no offence but is this supposed to be a tutorial?
Question
well
...
LETS FIX IT UP!! Razz Razz

Author:  ssr [ Thu Mar 10, 2005 10:10 pm ]
Post subject: 

Im srry if I been kinda harsh ZeroPldn
since this was ur first post
umm
Its better than my first post
Wink
there are some errors as mentioned above, fix them and u'd be ok

btw WELCOME! Laughing 8)

Author:  ZeroPldn [ Sat Mar 12, 2005 9:41 am ]
Post subject: 

ok ill fix it then, but since its allready been fixed by person (ty vm), theres no use reposting it. im sry if my first post was such a faliure ill try to be better next time. Embarassed ty person, here, have my bits.

Author:  Martin [ Sat Mar 12, 2005 10:54 am ]
Post subject: 

Hah no worries Smile


: