|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (7 bit)
|
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.
|
|
|
|
|
|
#2 |
|
SQL nutcase
|
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
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 Code:
for A = 1 to 4
print "A has a value of " & A
next
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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|