Loop application?

Questions about programming languages and debugging
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8085
Joined: 27 Aug 2005, 16:00
16
Contact:

Loop application?

Post 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? = /

User avatar
FrankB
Ph. D. in Sucko'logics
Ph. D. in Sucko'logics
Posts: 315
Joined: 06 Mar 2006, 17:00
15
Location: Belgistahn
Contact:

Re: Loop application?

Post 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

User avatar
ayu
Staff
Staff
Posts: 8085
Joined: 27 Aug 2005, 16:00
16
Contact:

Post 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. :/

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11609
Joined: 06 Apr 2005, 16:00
16
Location: The zone.
Contact:

Post by bad_brain »

what programming language?

User avatar
ayu
Staff
Staff
Posts: 8085
Joined: 27 Aug 2005, 16:00
16
Contact:

Post by ayu »

Visual basic

User avatar
H4evr
On the way to fame!
On the way to fame!
Posts: 43
Joined: 30 Apr 2006, 16:00
15
Location: Portugal
Contact:

Post 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

User avatar
FrankB
Ph. D. in Sucko'logics
Ph. D. in Sucko'logics
Posts: 315
Joined: 06 Mar 2006, 17:00
15
Location: Belgistahn
Contact:

Post 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

User avatar
H4evr
On the way to fame!
On the way to fame!
Posts: 43
Joined: 30 Apr 2006, 16:00
15
Location: Portugal
Contact:

Post 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

User avatar
FrankB
Ph. D. in Sucko'logics
Ph. D. in Sucko'logics
Posts: 315
Joined: 06 Mar 2006, 17:00
15
Location: Belgistahn
Contact:

Post 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

User avatar
FrankB
Ph. D. in Sucko'logics
Ph. D. in Sucko'logics
Posts: 315
Joined: 06 Mar 2006, 17:00
15
Location: Belgistahn
Contact:

Post 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

User avatar
H4evr
On the way to fame!
On the way to fame!
Posts: 43
Joined: 30 Apr 2006, 16:00
15
Location: Portugal
Contact:

Post 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.

User avatar
H4evr
On the way to fame!
On the way to fame!
Posts: 43
Joined: 30 Apr 2006, 16:00
15
Location: Portugal
Contact:

Post 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...

User avatar
FrankB
Ph. D. in Sucko'logics
Ph. D. in Sucko'logics
Posts: 315
Joined: 06 Mar 2006, 17:00
15
Location: Belgistahn
Contact:

Post 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

User avatar
H4evr
On the way to fame!
On the way to fame!
Posts: 43
Joined: 30 Apr 2006, 16:00
15
Location: Portugal
Contact:

Post by H4evr »

Thanks. :wink:
I really must upgrade to .NET ...

Post Reply