Author |
Message |
hpdudette
|
Posted: Thu May 22, 2003 6:57 pm Post subject: how do i solve this loop |
|
|
this is the problem:
write a program containing an infinite loop which out puts a series of integers starting at 5 and going up by 5 |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
kythoon
|
Posted: Thu May 22, 2003 7:01 pm Post subject: (No subject) |
|
|
code: |
var number : int := 5
put number
loop
number := number + 5
put number
end loop
|
i think this is what u want |
|
|
|
|
 |
Catalyst

|
Posted: Thu May 22, 2003 7:02 pm Post subject: (No subject) |
|
|
not gonna solve for u but heres a hint, use a loop
its REALLY simple
5 lines max
note: kythoon posted while i was posting |
|
|
|
|
 |
hpdudette
|
Posted: Thu May 22, 2003 7:02 pm Post subject: (No subject) |
|
|
thank you soooooo much |
|
|
|
|
 |
netninja
|
Posted: Mon Feb 16, 2004 7:55 am Post subject: (No subject) |
|
|
Would it not be easier to make it count 'by '5's instead of +5??? Its not even sarcasm, i'd like to know. If the numbers start getting big, will the program count faster 'by' numbers, or + the numbers?? |
|
|
|
|
 |
Tony

|
|
|
|
 |
Cervantes

|
Posted: Mon Feb 16, 2004 3:45 pm Post subject: (No subject) |
|
|
Well I think you learned a bit from my tutorial unfortunately, I think you''re getting for loops and loops confused.
The 'by 5' you are getting from a for loop when you do something like this
code: |
for counter : 1 .. 100 by 5
%blah blah blah
end for
|
That would work, except you can't use for loops in this problem because it asks to repeat an infinate number of times.
Loops = go on forever until the exit when statement is true
for loops = repeat a defined number of times. (can't set it to be 1 .. infinity) |
|
|
|
|
 |
netninja
|
Posted: Tue Feb 17, 2004 6:57 pm Post subject: (No subject) |
|
|
Yes, that was my question i think, if it was possible to do an infinite loop with the 'by', but i soon realized i had to do the num:=num+5 method. I already understand that. But thanks anyway. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
netninja
|
Posted: Wed Feb 18, 2004 4:08 pm Post subject: (No subject) |
|
|
How do you make a loop that generates random integers. My code isnt good at all. I tried doing a for loop, like 1..5, (so i generate 5 random numbers) and randint, but my code is all wrong, 0 % accurate. Can someone help me with that? |
|
|
|
|
 |
Cervantes

|
Posted: Wed Feb 18, 2004 4:20 pm Post subject: (No subject) |
|
|
code: |
var randnum : int
loop
randnum := Rand.Int (lownum, highnum)
%could also do it like this:
%randint (randnum, lownum, highnum)
put randnum
end loop
|
or if you want to use a for loop
code: |
var randnum : int
for i : low .. high
randnum := Rand.Int (lownum, highnum)
put randnum
end for
|
|
|
|
|
|
 |
netninja
|
Posted: Wed Feb 18, 2004 8:44 pm Post subject: (No subject) |
|
|
But i would like to make it give 5 random integers. I already know how to put 1 AHHHHhhhhHHHH, nevermind, i just noticed something. Thanks alot Cervantes. Sorry for my stupidity. heh, so that code wouldnt work with randint? Only Rand.Int. And i just realized why it fits into this particular code.
Thanks again |
|
|
|
|
 |
TheZsterBunny

|
Posted: Thu Feb 19, 2004 8:21 am Post subject: This may be too late but, |
|
|
This is something you could use
code: | var low := 1
var high := 5
var rhandom : array low..high of int
for randemnity: low..high
rhandom(randemnity) := Rand.Int(1,5)
end for
|
That would work quite well, but arrays take up a great deal of space.
-z0rQ |
|
|
|
|
 |
|