Loop application?
Loop application?
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? = /
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? = /
- FrankB
- Ph. D. in Sucko'logics
- Posts: 315
- Joined: 06 Mar 2006, 17:00
- 18
- Location: Belgistahn
- Contact:
Re: Loop application?
Remember this very good for your entire carreer in programming : a loop is a 'while' in disguise.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? = /
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);
}
--
FrankB
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
- FrankB
- Ph. D. in Sucko'logics
- Posts: 315
- Joined: 06 Mar 2006, 17:00
- 18
- Location: Belgistahn
- Contact:
You understand the half of what i posted ?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. :/
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
You can also think it as if statements, labels and gotos although this is unpractical for using in your programs.
Loop code:
Same code but using if, label and goto:
Loop code:
Code: Select all
dim d as integer
d = 0
do
d = d + 1
loop while d < 100
Code: Select all
dim d as integer
d = 0
do_loop:
d = d + 1
if d < 100 then goto do_loop
- FrankB
- Ph. D. in Sucko'logics
- Posts: 315
- Joined: 06 Mar 2006, 17:00
- 18
- Location: Belgistahn
- Contact:
Hello H4evr,H4evr wrote:You can also think it as if statements, labels and gotos although this is unpractical for using in your programs.
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
- FrankB
- Ph. D. in Sucko'logics
- Posts: 315
- Joined: 06 Mar 2006, 17:00
- 18
- Location: Belgistahn
- Contact:
What you are asking for is hassle and thus making endless loops on purpose.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. :/
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
--
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.FrankB wrote:Hello H4evr,H4evr wrote:You can also think it as if statements, labels and gotos although this is unpractical for using in your programs.
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
Maybe this sounds stupid but the example you gave is VB.NET?? Sorry, but I use vb6 and would like to know...FrankB wrote:What you are asking for is hassle and thus making endless loops on purpose.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. :/
that wil do the job in VB :it doesn't takes much to do stupid things with your computer, just avoid good guidance and burn your processor.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
--
FrankB
- FrankB
- Ph. D. in Sucko'logics
- Posts: 315
- Joined: 06 Mar 2006, 17:00
- 18
- Location: Belgistahn
- Contact:
Yes, is there a typo somewhere ?H4evr wrote: Maybe this sounds stupid but the example you gave is VB.NET??
Okay, it is indeed
Console.Write("I am number :" & i) and not
Console.Write("I am whatever", i)
VisualBasic.NET yes, versus console applications, not Forms.H4evr wrote: Sorry, but I use vb6 and would like to know...
--
FrankB