Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 08-09-2001, 03:49 AM   #1
Member (7 bit)
 
tedthebear's Avatar
 
Join Date: Aug 2001
Location: Los Angeles
Posts: 77
Send a message via AIM to tedthebear
Question Loops

I am a beginner at this. Can somebody give me a simple example of a loop in programming? I have been reading up on branch instructions and am somewhat confused. Thanks.
tedthebear is offline   Reply With Quote
Old 08-09-2001, 04:53 AM   #2
SQL nutcase
 
mosquito's Avatar
 
Join Date: Sep 2000
Location: Belgium
Posts: 1,136
Send a message via AIM to mosquito
The most used loops are a "for loop" and a "do while loop"

I'll give an example in Visual basic (because it's easy to understand)

Do while loop
Code:
A = 1
B = 5
Do While A < B
    print "A has a value of " & A
    A = A + 1
Loop
with this loop, A will be raised by 1 every time it loops until it is bigger than or equal to B. The output of this loop will be something like
Code:
A has a value of 1
A has a value of 2
A has a value of 3
A has a value of 4
Another popular loop system is the for loop
Code:
for A = 1 to 4 
    print "A has a value of " & A
next
This code will produce the exact same result.

The big advantage of the while loop is that you can compare anything to end your loop. You can use this loop to do something until a user strokes a key (read out the keystroke within the loop, and set a value to true and use the "while a <> true do")
The advantage of the for loop is that you don't have to increase the value yourself.

I hope this makes something clear. If you don't understand it, please post what part of the example you are having difficulties with.
mosquito is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:11 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2