Page 1 of 1

Loop application?

Posted: 03 Jun 2006, 12:01
by ayu
How do i loop my application? = /

when i put "loop" after my app it says "loop without do"

when i put "do loop" it says "expected: while or until end of statement"

can anyone help me? = /

Re: Loop application?

Posted: 03 Jun 2006, 12:52
by FrankB
neo130 wrote:How do i loop my application? = /

when i put "loop" after my app it says "loop without do"
when i put "do loop" it says "expected: while or until end of statement"
can anyone help me? = /
Remember this very good for your entire carreer in programming : a loop is a 'while' in disguise.

Now :
`loop' expects a statement that has to be evaluated .
Think of "loop until something / loop unless something".
So if you just write loop, the program/script asks "Loop what, buddy ?".

If you type " do loop". Same thing. Think "Do while this fits/ doesn't fit".

Example : (JavaScript) to keep it simple ;-)

Code: Select all

function loopMe(){
var a= new Array(10);
var b = new Number();
 while (b<a.length){
 b++;
 window.alert('i am number'+b);
 }
}
// is the same as :
function loopMe(){
var a= new Array(10);
var b = new Number();
do {
b++;
window.alert('i am number :'+b);
}
while (b<a.length);
}
Try it out.

--
FrankB

Posted: 03 Jun 2006, 13:14
by ayu
as my English isn't as great as yours, i do not fully understand what you mean, but half. What i am asking for is a code to "reroll" what the program just did, as in if the program makes a msgbox, it should do that over and over again, until i shutdown the application. :/

Posted: 03 Jun 2006, 13:17
by bad_brain
what programming language?

Posted: 03 Jun 2006, 13:21
by ayu
Visual basic

Posted: 03 Jun 2006, 14:18
by H4evr
Most common forms of do-loops in VB:

Code: Select all

do while xxx

loop

do until xxx

loop

do


loop while xxx

do 


loop until xxx

Posted: 04 Jun 2006, 04:54
by FrankB
neo130 wrote:as my English isn't as great as yours, i do not fully understand what you mean, but half. What i am asking for is a code to "reroll" what the program just did, as in if the program makes a msgbox, it should do that over and over again, until i shutdown the application. :/
You understand the half of what i posted ?
So i hope you undertood the most important part, here :

Remember this very good for your entire carreer in programming : a loop is a 'while' in disguise.
`loop' expects a statement that has to be evaluated .
Think of "loop until something / loop unless something".
So if you just write loop, the program/script asks "Loop what, buddy ?".
If you type " do loop". Same thing. Think "Do while this fits/ doesn't fit".

And that is universally valid (often called `logic')

--
FrankB

Posted: 04 Jun 2006, 08:29
by H4evr
You can also think it as if statements, labels and gotos although this is unpractical for using in your programs.

Loop code:

Code: Select all

dim d as integer

d = 0
do
 d = d + 1
loop while d < 100
Same code but using if, label and goto:

Code: Select all

dim d as integer

d = 0
do_loop:
 d = d + 1
if d < 100 then goto do_loop

Posted: 04 Jun 2006, 10:14
by FrankB
H4evr wrote:You can also think it as if statements, labels and gotos although this is unpractical for using in your programs.
Hello H4evr,
I don't think that labels are useless at all, in Perl for examble, they are exquisite handlers for the flow control of a program. Labels and handles are very handy, but under 100 lines of code : they look useless indeed.

"gotos" on the other hand, that is indeed a bit old and pretty redundant. Makes me think of BASIC :-)) & `spaghetti code'.

--
FrankB

Posted: 04 Jun 2006, 10:29
by FrankB
neo130 wrote: What i am asking for is a code to "reroll" what the program just did, as in if the program makes a msgbox, it should do that over and over again, until i shutdown the application. :/
What you are asking for is hassle and thus making endless loops on purpose.
that wil do the job in VB :

Code: Select all

Sub Main()
dim i as int = 0
function loopMeDead()
do 
 i = i + 1
console.write("I am ", i)
loop while i > -1
end function

loopMeDead()
End Sub

'...press F5 and  bye bye
it doesn't takes much to do stupid things with your computer, just avoid good guidance and burn your processor.

--
FrankB

Posted: 04 Jun 2006, 11:23
by H4evr
FrankB wrote:
H4evr wrote:You can also think it as if statements, labels and gotos although this is unpractical for using in your programs.
Hello H4evr,
I don't think that labels are useless at all, in Perl for examble, they are exquisite handlers for the flow control of a program. Labels and handles are very handy, but under 100 lines of code : they look useless indeed.

"gotos" on the other hand, that is indeed a bit old and pretty redundant. Makes me think of BASIC :-)) & `spaghetti code'.

--
FrankB
I use labels and gotos on my VB code many times because of error handling. But in this case, as I said, it's not practical to use it in this situation. It's just to understand how a do-loop works.

Posted: 04 Jun 2006, 11:24
by H4evr
FrankB wrote:
neo130 wrote: What i am asking for is a code to "reroll" what the program just did, as in if the program makes a msgbox, it should do that over and over again, until i shutdown the application. :/
What you are asking for is hassle and thus making endless loops on purpose.
that wil do the job in VB :

Code: Select all

Sub Main()
dim i as int = 0
function loopMeDead()
do 
 i = i + 1
console.write("I am ", i)
loop while i > -1
end function

loopMeDead()
End Sub

'...press F5 and  bye bye
it doesn't takes much to do stupid things with your computer, just avoid good guidance and burn your processor.

--
FrankB
Maybe this sounds stupid but the example you gave is VB.NET?? Sorry, but I use vb6 and would like to know...

Posted: 04 Jun 2006, 12:24
by FrankB
H4evr wrote: Maybe this sounds stupid but the example you gave is VB.NET??
Yes, is there a typo somewhere ?
Okay, it is indeed
Console.Write("I am number :" & i) and not
Console.Write("I am whatever", i)
H4evr wrote: Sorry, but I use vb6 and would like to know...
VisualBasic.NET yes, versus console applications, not Forms.

--
FrankB

Posted: 04 Jun 2006, 14:55
by H4evr
Thanks. :wink:
I really must upgrade to .NET ...